Class: Puppet::Pops::Loader::Loader
- Defined in:
- lib/puppet/pops/loader/loader.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NamedEntry
Constant Summary collapse
- LOADABLE_KINDS =
Describes the kinds of things that loaders can load
[:func_4x, :func_4xpp, :type_pp, :resource_type_pp].freeze
Instance Attribute Summary collapse
- #loader_name ⇒ Object readonly
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.
-
#initialize(loader_name) ⇒ Loader
constructor
A new instance of Loader.
-
#inspect ⇒ Object
Loaders may contain references to the environment they load items within.
-
#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.
-
#loadables ⇒ Object
private
A loader is by default a loader for all kinds of loadables.
-
#loaded_entry(typed_name, check_dependencies = false) ⇒ NamedEntry?
Returns an already loaded entry if one exists, or 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.
-
#to_s ⇒ Object
A loader may want to implement its own version with more detailed information.
Constructor Details
#initialize(loader_name) ⇒ Loader
Returns a new instance of Loader.
35 36 37 |
# File 'lib/puppet/pops/loader/loader.rb', line 35 def initialize(loader_name) @loader_name = loader_name.freeze end |
Instance Attribute Details
#loader_name ⇒ Object (readonly)
29 30 31 |
# File 'lib/puppet/pops/loader/loader.rb', line 29 def loader_name @loader_name end |
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.
91 92 93 94 95 96 97 |
# File 'lib/puppet/pops/loader/loader.rb', line 91 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.
108 109 110 |
# File 'lib/puppet/pops/loader/loader.rb', line 108 def find(typed_name) raise NotImplementedError, "Class #{self.class.name} must implement method #find" 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.
145 146 147 |
# File 'lib/puppet/pops/loader/loader.rb', line 145 def get_entry(typed_name) raise NotImplementedError.new end |
#inspect ⇒ Object
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).
169 170 171 |
# File 'lib/puppet/pops/loader/loader.rb', line 169 def inspect self.to_s 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.
52 53 54 55 56 |
# File 'lib/puppet/pops/loader/loader.rb', line 52 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.
66 67 68 |
# File 'lib/puppet/pops/loader/loader.rb', line 66 def load_typed(typed_name) raise NotImplementedError, "Class #{self.class.name} must implement method #load_typed" end |
#loadables ⇒ 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.
A loader is by default a loader for all kinds of loadables. An implementation may override if it cannot load all kinds.
153 154 155 |
# File 'lib/puppet/pops/loader/loader.rb', line 153 def loadables LOADABLE_KINDS end |
#loaded_entry(typed_name, check_dependencies = false) ⇒ NamedEntry?
Returns an already loaded entry if one exists, or nil. This does not trigger loading of the given type/name.
78 79 80 |
# File 'lib/puppet/pops/loader/loader.rb', line 78 def loaded_entry(typed_name, check_dependencies = false) raise NotImplementedError, "Class #{self.class.name} must implement method #loaded_entry" end |
#parent ⇒ Object
Returns the parent of the loader, or nil, if this is the top most loader. This implementation returns nil.
113 114 115 |
# File 'lib/puppet/pops/loader/loader.rb', line 113 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.
121 122 123 |
# File 'lib/puppet/pops/loader/loader.rb', line 121 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.
134 135 136 |
# File 'lib/puppet/pops/loader/loader.rb', line 134 def set_entry(type, name, value, origin = nil) raise NotImplementedError.new end |
#to_s ⇒ Object
A loader may want to implement its own version with more detailed information.
158 159 160 |
# File 'lib/puppet/pops/loader/loader.rb', line 158 def to_s loader_name end |