class Puppet::Pops::Loader::Loader
Constants
- LOADABLE_KINDS
Describes the kinds of things that loaders can load
Attributes
Public Class Methods
@param [String] name the name of the loader. Must be unique among all loaders maintained by a {Loader} instance
# File lib/puppet/pops/loader/loader.rb 35 def initialize(loader_name, environment) 36 @loader_name = loader_name.freeze 37 @environment = environment 38 end
Public Instance Methods
Produces the value associated with the given name if defined **in this loader**, or nil if not defined. This lookup does not trigger any loading, or search of the given name. An implementor of this method may not search or look up in any other loader, and it may not define the name.
@param typed_name [TypedName] - the type, name combination to lookup
@api private
# File lib/puppet/pops/loader/loader.rb 114 def [](typed_name) 115 found = get_entry(typed_name) 116 if found 117 found.value 118 else 119 nil 120 end 121 end
Search all places where this loader would find values of a given type and return a list the found values for which the given block returns true. All found entries will be returned if no block is given.
Errors that occur function discovery will either be logged as warnings or collected by the optional `error_collector` array. When provided, it will receive {Puppet::DataTypes::Error} instances describing each error in detail and no warnings will be logged.
@param type [Symbol] the type of values to search for @param error_collector [Array<Puppet::DataTypes::Error>] an optional array that will receive errors during load @param name_authority [String] the name authority, defaults to the pcore runtime @yield [typed_name] optional block to filter the results @yieldparam [TypedName] typed_name the typed name of a found entry @yieldreturn [Boolean] `true` to keep the entry, `false` to discard it. @return [Array<TypedName>] the list of names of discovered values
# File lib/puppet/pops/loader/loader.rb 55 def discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block) 56 return EMPTY_ARRAY 57 end
Searches for the given name in this loader's context (parents should already have searched their context(s) without producing a result when this method is called). An implementation of find typically caches the result.
@param typed_name [TypedName] the type, name combination to lookup @return [NamedEntry, nil] the entry for the loaded entry, or nil if not found
@api private
# File lib/puppet/pops/loader/loader.rb 132 def find(typed_name) 133 raise NotImplementedError, "Class #{self.class.name} must implement method #find" 134 end
Produces a NamedEntry
if a value is bound to the given name, or nil if nothing is bound.
@param typed_name [TypedName] the type, name combination to lookup @return [NamedEntry, nil] the value bound in an entry
@api private
# File lib/puppet/pops/loader/loader.rb 176 def get_entry(typed_name) 177 raise NotImplementedError.new 178 end
Loaders
may contain references to the environment they load items within. Consequently, calling Kernel#inspect may return strings that are large enough to cause OutOfMemoryErrors on some platforms.
We do not call alias_method here as that would copy the content of to_s
at this point to inspect (ie children would print out `loader_name` rather than their version of to_s
if they chose to implement it).
# File lib/puppet/pops/loader/loader.rb 200 def inspect 201 self.to_s 202 end
Produces the value associated with the given name if already loaded, or available for loading by this loader, one of its parents, or other loaders visible to this loader. This is the method an external party should use to “get” the named element.
An implementor of this method should first check if the given name is already loaded by self, or a parent loader, and if so return that result. If not, it should call `find` to perform the loading.
@param type [:Symbol] the type to load @param name [String, Symbol] the name of the entity to load @return [Object, nil] the value or nil if not found
@api public
# File lib/puppet/pops/loader/loader.rb 72 def load(type, name) 73 synchronize do 74 result = load_typed(TypedName.new(type, name.to_s)) 75 if result 76 result.value 77 end 78 end 79 end
Loads the given typed name, and returns a NamedEntry
if found, else returns nil. This the same a `load`, but returns a NamedEntry
with origin/value information.
@param typed_name [TypedName] - the type, name combination to lookup @return [NamedEntry, nil] the entry containing the loaded value, or nil if not found
@api public
# File lib/puppet/pops/loader/loader.rb 89 def load_typed(typed_name) 90 raise NotImplementedError, "Class #{self.class.name} must implement method #load_typed" 91 end
A loader is by default a loader for all kinds of loadables. An implementation may override if it cannot load all kinds.
@api private
# File lib/puppet/pops/loader/loader.rb 184 def loadables 185 LOADABLE_KINDS 186 end
Returns an already loaded entry if one exists, or nil. This does not trigger loading of the given type/name.
@param typed_name [TypedName] - the type, name combination to lookup @param check_dependencies [Boolean] - if dependencies should be checked in addition to here and parent @return [NamedEntry, nil] the entry containing the loaded value, or nil if not found @api public
# File lib/puppet/pops/loader/loader.rb 101 def loaded_entry(typed_name, check_dependencies = false) 102 raise NotImplementedError, "Class #{self.class.name} must implement method #loaded_entry" 103 end
Returns the parent of the loader, or nil, if this is the top most loader. This implementation returns nil.
# File lib/puppet/pops/loader/loader.rb 137 def parent 138 nil 139 end
Produces the private loader for loaders that have a one (the visibility given to loaded entities). For loaders that does not provide a private loader, self is returned.
@api private
# File lib/puppet/pops/loader/loader.rb 145 def private_loader 146 self 147 end
Binds a value to a name. The name should not start with '::', but may contain multiple segments.
@param type [:Symbol] the type of the entity being set @param name [String, Symbol] the name of the entity being set @param origin [URI, uri, String] the origin of the set entity, a URI, or provider of URI, or URI in string form @return [NamedEntry, nil] the created entry
@api private
# File lib/puppet/pops/loader/loader.rb 165 def set_entry(type, name, value, origin = nil) 166 raise NotImplementedError.new 167 end
Lock around a block This exists so some subclasses that are set up statically and don't actually load can override it
# File lib/puppet/pops/loader/loader.rb 152 def synchronize(&block) 153 @environment.lock.synchronize(&block) 154 end
A loader may want to implement its own version with more detailed information.
# File lib/puppet/pops/loader/loader.rb 189 def to_s 190 loader_name 191 end