Class: Puppet::Pops::Loader::BaseLoader Private

Inherits:
Loader show all
Defined in:
lib/puppet/pops/loader/base_loader.rb

Overview

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.

BaseLoader

An abstract implementation of Puppet::Pops::Loader::Loader

A derived class should implement ‘find(typed_name)` and set entries, and possible handle “miss caching”.

Constant Summary

Constants inherited from Loader

Loader::LOADABLE_KINDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Loader

#[], #find, #load, #loadables, #private_loader

Constructor Details

#initialize(parent_loader, loader_name) ⇒ 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
23
# File 'lib/puppet/pops/loader/base_loader.rb', line 17

def initialize(parent_loader, loader_name)
  @parent = parent_loader # the higher priority loader to consult
  @named_values = {}      # hash name => NamedEntry
  @last_name = nil        # the last name asked for (optimization)
  @last_result = nil      # the value of the last name (optimization)
  @loader_name = loader_name # the name of the loader (not the name-space it is a loader for)
end

Instance Attribute Details

#loader_nameObject (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.

An internal name used for debugging and error message purposes



15
16
17
# File 'lib/puppet/pops/loader/base_loader.rb', line 15

def loader_name
  @loader_name
end

#parentObject (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



12
13
14
# File 'lib/puppet/pops/loader/base_loader.rb', line 12

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.



58
59
60
# File 'lib/puppet/pops/loader/base_loader.rb', line 58

def add_entry(type, name, value, origin)
  set_entry(Puppet::Pops::Loader::Loader::TypedName.new(type, name), value, origin)
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)



45
46
47
# File 'lib/puppet/pops/loader/base_loader.rb', line 45

def get_entry(typed_name)
  @named_values[typed_name]
end

#load_typed(typed_name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet/pops/loader/base_loader.rb', line 27

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.
  if typed_name == @last_name
    @last_result
  else
    @last_name = typed_name
    @last_result = internal_load(typed_name)
  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



66
67
68
69
70
# File 'lib/puppet/pops/loader/base_loader.rb', line 66

def promote_entry(named_entry)
  typed_name = named_entry.typed_name
  if entry = @named_values[typed_name] then fail_redefine(entry); end
  @named_values[typed_name] = named_entry
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.



51
52
53
54
# File 'lib/puppet/pops/loader/base_loader.rb', line 51

def set_entry(typed_name, value, origin = nil)
  if entry = @named_values[typed_name] then fail_redefined(entry); end
  @named_values[typed_name] = Puppet::Pops::Loader::Loader::NamedEntry.new(typed_name, value, origin)
end