class Puppet::Parser::TypeLoader

Public Class Methods

new(env) click to toggle source
# File lib/puppet/parser/type_loader.rb, line 113
def initialize(env)
  self.environment = env
  @loading_helper = Helper.new
end

Public Instance Methods

import(file, current_file = nil) click to toggle source

Import our files.

# File lib/puppet/parser/type_loader.rb, line 65
def import(file, current_file = nil)
  return if Puppet[:ignoreimport]

  # use a path relative to the file doing the importing
  if current_file
    dir = current_file.sub(%r{[^/]+$},'').sub(/\/$/, '')
  else
    dir = "."
  end
  if dir == ""
    dir = "."
  end

  pat = file
  modname, files = Puppet::Parser::Files.find_manifests(pat, :cwd => dir, :environment => environment)
  if files.size == 0
    raise Puppet::ImportError.new("No file(s) found for import of '#{pat}'")
  end

  loaded_asts = []
  files.each do |file|
    unless Puppet::Util.absolute_path?(file)
      file = File.join(dir, file)
    end
    @loading_helper.do_once(file) do
      loaded_asts << parse_file(file)
    end
  end
  loaded_asts.inject([]) do |loaded_types, ast|
    loaded_types + known_resource_types.import_ast(ast, modname)
  end
end
import_all() click to toggle source
# File lib/puppet/parser/type_loader.rb, line 98
def import_all
  # And then load all files from each module, but (relying on system
  # behavior) only load files from the first module of a given name.  E.g.,
  # given first/foo and second/foo, only files from first/foo will be loaded.
  environment.modules.each do |mod|
    Find.find(mod.manifests) do |path|
      if path =~ /\.pp$/ or path =~ /\.rb$/
        import(path)
      end
    end
  end
end
parse_file(file) click to toggle source
# File lib/puppet/parser/type_loader.rb, line 138
def parse_file(file)
  Puppet.debug("importing '#{file}' in environment #{environment}")
  parser = Puppet::Parser::Parser.new(environment)
  parser.file = file
  return parser.parse
end
try_load_fqname(type, fqname) click to toggle source

Try to load the object with the given fully qualified name.

# File lib/puppet/parser/type_loader.rb, line 119
def try_load_fqname(type, fqname)
  return nil if fqname == "" # special-case main.
  name2files(fqname).each do |filename|
    begin
      imported_types = import(filename)
      if result = imported_types.find { |t| t.type == type and t.name == fqname }
        Puppet.debug "Automatically imported #{fqname} from #{filename} into #{environment}"
        return result
      end
    rescue Puppet::ImportError => detail
      # We couldn't load the item
      # I'm not convienced we should just drop these errors, but this
      # preserves existing behaviours.
    end
  end
  # Nothing found.
  return nil
end