Class: Puppet::Pops::Loader::Loader
- Defined in:
- lib/puppet/pops/loader/loader.rb
Overview
Loader
A Loader is responsible for loading “entities” (“instantiable and executable objects in the puppet language” which are type, hostclass, definition, function, and bindings.
The main method for users of a Loader is the load or ‘load_typed methods`, which returns a previously loaded entity of a given type/name, and searches and loads the entity if not already loaded.
private entities
TODO: handle loading of entities that are private. Suggest that all calls pass an origin_loader (the loader where request originated (or symbol :public). A module loader has one (or possibly a list) of what is considered to represent private loader - i.e. the dependency loader for a module. If an entity is private it should be stored with this status, and an error should be raised if the origin_loader is not on the list of accepted “private” loaders. The private loaders can not be given at creation time (they are parented by the loader in question). Another alternative is to check if the origin_loader is a child loader, but this requires bidirectional links between loaders or a search if loader with private entity is a parent of the origin_loader).
Direct Known Subclasses
Defined Under Namespace
Classes: NamedEntry, TypedName
Instance Method Summary collapse
-
#[](typed_name) ⇒ Object
private
Produces the value associated with the given name if defined **in this loader**, or nil if not defined.
-
#find(typed_name) ⇒ NamedEntry?
private
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).
-
#get_entry(typed_name) ⇒ NamedEntry?
private
Produces a NamedEntry if a value is bound to the given name, or nil if nothing is bound.
-
#load(type, name) ⇒ Object?
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.
-
#load_typed(typed_name) ⇒ NamedEntry?
Loads the given typed name, and returns a NamedEntry if found, else returns nil.
-
#parent ⇒ Object
Returns the parent of the loader, or nil, if this is the top most loader.
-
#private_loader ⇒ Object
private
Produces the private loader for loaders that have a one (the visibility given to loaded entities).
-
#set_entry(type, name, value, origin = nil) ⇒ NamedEntry?
private
Binds a value to a name.
Instance Method Details
#[](typed_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
64 65 66 67 68 69 70 |
# File 'lib/puppet/pops/loader/loader.rb', line 64 def [] (typed_name) if found = get_entry(typed_name) found.value else nil end end |
#find(typed_name) ⇒ NamedEntry?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
81 82 83 |
# File 'lib/puppet/pops/loader/loader.rb', line 81 def find(typed_name) raise NotImplementedError.new end |
#get_entry(typed_name) ⇒ NamedEntry?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Produces a NamedEntry if a value is bound to the given name, or nil if nothing is bound.
118 119 120 |
# File 'lib/puppet/pops/loader/loader.rb', line 118 def get_entry(typed_name) raise NotImplementedError.new end |
#load(type, name) ⇒ Object?
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.
37 38 39 40 41 |
# File 'lib/puppet/pops/loader/loader.rb', line 37 def load(type, name) if result = load_typed(TypedName.new(type, name.to_s)) result.value end end |
#load_typed(typed_name) ⇒ NamedEntry?
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.
51 52 53 |
# File 'lib/puppet/pops/loader/loader.rb', line 51 def load_typed(typed_name) raise NotImplementedError.new end |
#parent ⇒ Object
Returns the parent of the loader, or nil, if this is the top most loader. This implementation returns nil.
86 87 88 |
# File 'lib/puppet/pops/loader/loader.rb', line 86 def parent nil end |
#private_loader ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
94 95 96 |
# File 'lib/puppet/pops/loader/loader.rb', line 94 def private_loader self end |
#set_entry(type, name, value, origin = nil) ⇒ NamedEntry?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Binds a value to a name. The name should not start with ‘::’, but may contain multiple segments.
107 108 109 |
# File 'lib/puppet/pops/loader/loader.rb', line 107 def set_entry(type, name, value, origin = nil) raise NotImplementedError.new end |