Class: Puppet::Pops::Loader::StaticLoader

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

Constant Summary collapse

BUILTIN_TYPE_NAMES =
%w{
  Component
  Exec
  File
  Filebucket
  Group
  Node
  Notify
  Package
  Resources
  Schedule
  Service
  Stage
  Tidy
  User
  Whit
}.freeze
BUILTIN_TYPE_NAMES_LC =
Set.new(BUILTIN_TYPE_NAMES.map { |n| n.downcase }).freeze
BUILTIN_ALIASES =
{
  'Data' => 'Variant[ScalarData,Undef,Hash[String,Data],Array[Data]]',
  'RichDataKey' => 'Variant[String,Numeric]',
  'RichData' => 'Variant[Scalar,SemVerRange,Binary,Sensitive,Type,TypeSet,URI,Object,Undef,Default,Hash[RichDataKey,RichData],Array[RichData]]',

  # Backward compatible aliases.
  'Puppet::LookupKey' => 'RichDataKey',
  'Puppet::LookupValue' => 'RichData'
}.freeze

Constants inherited from Loader

Loader::LOADABLE_KINDS

Instance Attribute Summary collapse

Attributes inherited from Loader

#loader_name

Instance Method Summary collapse

Methods inherited from Loader

#[], #inspect, #load, #loadables, #private_loader

Constructor Details

#initializeStaticLoader

Returns a new instance of StaticLoader.



39
40
41
42
43
# File 'lib/puppet/pops/loader/static_loader.rb', line 39

def initialize
  @loaded = {}
  @runtime_3_initialized = false
  create_built_in_types
end

Instance Attribute Details

#loadedObject (readonly)



38
39
40
# File 'lib/puppet/pops/loader/static_loader.rb', line 38

def loaded
  @loaded
end

Instance Method Details

#discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/puppet/pops/loader/static_loader.rb', line 45

def discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY)
  # Static loader only contains runtime types
  return EMPTY_ARRAY unless type == :type && name_authority == name_authority = Pcore::RUNTIME_NAME_AUTHORITY #rubocop:disable Lint/AssignmentInCondition

  typed_names = type == :type && name_authority == Pcore::RUNTIME_NAME_AUTHORITY ? @loaded.keys : EMPTY_ARRAY
  block_given? ? typed_names.select { |tn| yield(tn) } : typed_names
end

#find(name) ⇒ Object



65
66
67
68
# File 'lib/puppet/pops/loader/static_loader.rb', line 65

def find(name)
  # There is nothing to search for, everything this loader knows about is already available
  nil
end

#get_entry(typed_name) ⇒ Object



57
58
59
# File 'lib/puppet/pops/loader/static_loader.rb', line 57

def get_entry(typed_name)
  load_constant(typed_name)
end

#load_typed(typed_name) ⇒ Object



53
54
55
# File 'lib/puppet/pops/loader/static_loader.rb', line 53

def load_typed(typed_name)
  load_constant(typed_name)
end

#loaded_entry(typed_name, check_dependencies = false) ⇒ Object



78
79
80
# File 'lib/puppet/pops/loader/static_loader.rb', line 78

def loaded_entry(typed_name, check_dependencies = false)
  @loaded[typed_name]
end

#parentObject



70
71
72
# File 'lib/puppet/pops/loader/static_loader.rb', line 70

def parent
  nil # at top of the hierarchy
end

#register_aliasesObject



90
91
92
93
# File 'lib/puppet/pops/loader/static_loader.rb', line 90

def register_aliases
  aliases = BUILTIN_ALIASES.map { |name, string| add_type(name, Types::PTypeAliasType.new(name, Types::TypeFactory.type_reference(string), nil)) }
  aliases.each { |type| type.resolve(self) }
end

#runtime_3_initObject



82
83
84
85
86
87
88
# File 'lib/puppet/pops/loader/static_loader.rb', line 82

def runtime_3_init
  unless @runtime_3_initialized
    @runtime_3_initialized = true
    create_resource_type_references
  end
  nil
end

#set_entry(typed_name, value, origin = nil) ⇒ Object



61
62
63
# File 'lib/puppet/pops/loader/static_loader.rb', line 61

def set_entry(typed_name, value, origin = nil)
  @loaded[typed_name] = Loader::NamedEntry.new(typed_name, value, origin)
end

#to_sObject



74
75
76
# File 'lib/puppet/pops/loader/static_loader.rb', line 74

def to_s()
  "(StaticLoader)"
end