Class: Puppet::Pops::Loader::BaseLoader Private
- Defined in:
- lib/puppet/pops/loader/base_loader.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
DependencyLoader, ModuleLoaders::AbstractPathBasedModuleLoader, ModuleLoaders::EmptyLoader, PredefinedLoader, Runtime3TypeLoader, SimpleEnvironmentLoader, Types::PTypeSetType::TypeSetLoader
Constant Summary
Constants inherited from Loader
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
private
The parent loader.
Attributes inherited from Loader
Instance Method Summary collapse
- #add_entry(type, name, value, origin) ⇒ Object private
- #discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block) ⇒ Object private
-
#get_entry(typed_name) ⇒ Object
private
This method is final (subclasses should not override it).
-
#initialize(parent_loader, loader_name, environment) ⇒ BaseLoader
constructor
private
A new instance of BaseLoader.
- #load_typed(typed_name) ⇒ Object
- #loaded_entry(typed_name, check_dependencies = false) ⇒ Object
-
#promote_entry(named_entry) ⇒ Object
private
Promotes an already created entry (typically from another loader) to this loader.
- #remove_entry(typed_name) ⇒ Object private
- #set_entry(typed_name, value, origin = nil) ⇒ Object private
Methods inherited from Loader
#[], #find, #inspect, #load, #loadables, #private_loader, #synchronize, #to_s
Constructor Details
#initialize(parent_loader, loader_name, environment) ⇒ BaseLoader
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.
Returns a new instance of BaseLoader.
17 18 19 20 21 22 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 17 def initialize(parent_loader, loader_name, environment) super(loader_name, environment) @parent = parent_loader # the higher priority loader to consult @named_values = {} # hash name => NamedEntry @last_result = nil # the value of the last name (optimization) end |
Instance Attribute Details
#parent ⇒ Object (readonly)
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.
The parent loader
15 16 17 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 15 def parent @parent end |
Instance Method Details
#add_entry(type, name, value, origin) ⇒ 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.
99 100 101 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 99 def add_entry(type, name, value, origin) set_entry(TypedName.new(type, name), value, origin) end |
#discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block) ⇒ 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.
24 25 26 27 28 29 30 31 32 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 24 def discover(type, error_collector = nil, = Pcore::RUNTIME_NAME_AUTHORITY, &block) result = [] @named_values.each_pair do |key, entry| result << key unless entry.nil? || entry.value.nil? || key.type != type || (block_given? && !yield(key)) end result.concat(parent.discover(type, error_collector, , &block)) result.uniq! result end |
#get_entry(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.
This method is final (subclasses should not override it)
69 70 71 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 69 def get_entry(typed_name) @named_values[typed_name] end |
#load_typed(typed_name) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 36 def load_typed(typed_name) # The check for "last queried name" is an optimization when a module searches. First it checks up its parent # chain, then itself, and then delegates to modules it depends on. # These modules are typically parented by the same # loader as the one initiating the search. It is inefficient to again try to search the same loader for # the same name. synchronize do if @last_result.nil? || typed_name != @last_result.typed_name @last_result = internal_load(typed_name) else @last_result end end end |
#loaded_entry(typed_name, check_dependencies = false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 53 def loaded_entry(typed_name, check_dependencies = false) synchronize do if @named_values.has_key?(typed_name) @named_values[typed_name] elsif parent parent.loaded_entry(typed_name, check_dependencies) else nil end end end |
#promote_entry(named_entry) ⇒ 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.
Promotes an already created entry (typically from another loader) to this loader
117 118 119 120 121 122 123 124 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 117 def promote_entry(named_entry) synchronize do typed_name = named_entry.typed_name entry = @named_values[typed_name] if entry then fail_redefine(entry); end @named_values[typed_name] = named_entry end end |
#remove_entry(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.
105 106 107 108 109 110 111 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 105 def remove_entry(typed_name) synchronize do unless @named_values.delete(typed_name).nil? @last_result = nil unless @last_result.nil? || typed_name != @last_result.typed_name end end end |
#set_entry(typed_name, value, origin = nil) ⇒ 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.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/puppet/pops/loader/base_loader.rb', line 75 def set_entry(typed_name, value, origin = nil) synchronize do # It is never ok to redefine in the very same loader unless redefining a 'not found' entry = @named_values[typed_name] if entry fail_redefine(entry) unless entry.value.nil? end # Check if new entry shadows existing entry and fail # (unless special loader allows shadowing) if typed_name.type == :type && !allow_shadowing? entry = loaded_entry(typed_name) if entry fail_redefine(entry) unless entry.value.nil? # || entry.value == value end end @last_result = Loader::NamedEntry.new(typed_name, value, origin) @named_values[typed_name] = @last_result end end |