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(&: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

#environment, #loader_name

Instance Method Summary collapse

Methods inherited from Loader

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

Constructor Details

#initializeStaticLoader

Returns a new instance of StaticLoader.



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

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

Instance Attribute Details

#loadedObject (readonly)



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

def loaded
  @loaded
end

Instance Method Details

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



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

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

  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



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

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

#get_entry(typed_name) ⇒ Object



59
60
61
# File 'lib/puppet/pops/loader/static_loader.rb', line 59

def get_entry(typed_name)
  load_constant(typed_name)
end

#load_typed(typed_name) ⇒ Object



55
56
57
# File 'lib/puppet/pops/loader/static_loader.rb', line 55

def load_typed(typed_name)
  load_constant(typed_name)
end

#loaded_entry(typed_name, check_dependencies = false) ⇒ Object



80
81
82
# File 'lib/puppet/pops/loader/static_loader.rb', line 80

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

#parentObject



72
73
74
# File 'lib/puppet/pops/loader/static_loader.rb', line 72

def parent
  nil # at top of the hierarchy
end

#register_aliasesObject



92
93
94
95
# File 'lib/puppet/pops/loader/static_loader.rb', line 92

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



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

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



63
64
65
# File 'lib/puppet/pops/loader/static_loader.rb', line 63

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

#to_sObject



76
77
78
# File 'lib/puppet/pops/loader/static_loader.rb', line 76

def to_s
  "(StaticLoader)"
end