module Puppet::Pops::Pcore

Constants

KEY_PCORE_URI
KEY_PCORE_VERSION
PARSABLE_PCORE_VERSIONS
PCORE_URI
PCORE_VERSION
RUNTIME_NAME_AUTHORITY
TYPE_MEMBER_NAME
TYPE_QUALIFIED_REFERENCE
TYPE_SIMPLE_TYPE_NAME
TYPE_URI
TYPE_URI_ALIAS
TYPE_URI_RX

Public Class Methods

_pcore_type() click to toggle source
   # File lib/puppet/pops/pcore.rb
24 def self._pcore_type
25   @type
26 end
add_alias(name, type, loader, name_authority = RUNTIME_NAME_AUTHORITY) click to toggle source
    # File lib/puppet/pops/pcore.rb
116 def self.add_alias(name, type, loader, name_authority = RUNTIME_NAME_AUTHORITY)
117   add_type(Types::PTypeAliasType.new(name, nil, type), loader, name_authority)
118 end
add_object_type(name, body, loader) click to toggle source
    # File lib/puppet/pops/pcore.rb
112 def self.add_object_type(name, body, loader)
113   add_type(Types::PObjectType.new(name, Parser::EvaluatingParser.new.parse_string(body).body), loader)
114 end
add_type(type, loader, name_authority = RUNTIME_NAME_AUTHORITY) click to toggle source
    # File lib/puppet/pops/pcore.rb
120 def self.add_type(type, loader, name_authority = RUNTIME_NAME_AUTHORITY)
121   loader.set_entry(Loader::TypedName.new(:type, type.name, name_authority), type)
122   type
123 end
annotate(instance, annotations_hash) click to toggle source
   # File lib/puppet/pops/pcore.rb
28 def self.annotate(instance, annotations_hash)
29   annotations_hash.each_pair do |type, init_hash|
30     type.implementation_class.annotate(instance) { init_hash }
31   end
32   instance
33 end
create_object_type(loader, ir, impl_class, type_name, parent_name, attributes_hash = EMPTY_HASH, functions_hash = EMPTY_HASH, equality = nil) click to toggle source

Create and register a new `Object` type in the Puppet Type System and map it to an implementation class

@param loader [Loader::Loader] The loader where the new type will be registered @param ir [ImplementationRegistry] The implementation registry that maps this class to the new type @param impl_class [Class] The class that is the implementation of the type @param type_name [String] The fully qualified name of the new type @param parent_name [String,nil] The fully qualified name of the parent type @param attributes_hash [Hash{String => Object}] A hash of attribute definitions for the new type @param functions_hash [Hash{String => Object}] A hash of function definitions for the new type @param equality [Array<String>] An array with names of attributes that participate in equality comparison @return [PObjectType] the created type. Not yet resolved

@api private

    # File lib/puppet/pops/pcore.rb
102 def self.create_object_type(loader, ir, impl_class, type_name, parent_name, attributes_hash = EMPTY_HASH, functions_hash = EMPTY_HASH, equality = nil)
103   init_hash = {}
104   init_hash[Types::KEY_PARENT] = Types::PTypeReferenceType.new(parent_name) unless parent_name.nil?
105   init_hash[Types::KEY_ATTRIBUTES] = attributes_hash unless attributes_hash.empty?
106   init_hash[Types::KEY_FUNCTIONS] = functions_hash unless functions_hash.empty?
107   init_hash[Types::KEY_EQUALITY] = equality unless equality.nil?
108   ir.register_implementation(type_name, impl_class)
109   add_type(Types::PObjectType.new(type_name, init_hash), loader)
110 end
init(loader, ir) click to toggle source
   # File lib/puppet/pops/pcore.rb
59   def self.init(loader, ir)
60     add_alias('Pcore::URI_RX', TYPE_URI_RX, loader)
61     add_type(TYPE_URI_ALIAS, loader)
62     add_alias('Pcore::SimpleTypeName', TYPE_SIMPLE_TYPE_NAME, loader)
63     add_alias('Pcore::MemberName', TYPE_MEMBER_NAME, loader)
64     add_alias('Pcore::TypeName', TYPE_QUALIFIED_REFERENCE, loader)
65     add_alias('Pcore::QRef', TYPE_QUALIFIED_REFERENCE, loader)
66     Types::TypedModelObject.register_ptypes(loader, ir)
67 
68     @type = create_object_type(loader, ir, Pcore, 'Pcore', nil)
69 
70     ir.register_implementation_namespace('Pcore', 'Puppet::Pops::Pcore')
71     ir.register_implementation_namespace('Puppet::AST', 'Puppet::Pops::Model')
72     ir.register_implementation('Puppet::AST::Locator', 'Puppet::Pops::Parser::Locator::Locator19')
73     Resource.register_ptypes(loader, ir)
74     Lookup::Context.register_ptype(loader, ir);
75     Lookup::DataProvider.register_types(loader)
76 
77     add_object_type('Deferred', <<-PUPPET, loader)
78       {
79         attributes => {
80           # Fully qualified name of the function
81           name  => { type => Pattern[/\\A[$]?[a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)*\\z/] },
82           arguments => { type => Optional[Array[Any]], value => undef},
83         }
84       }
85     PUPPET
86 
87   end
init_env(loader) click to toggle source
   # File lib/puppet/pops/pcore.rb
35   def self.init_env(loader)
36     if Puppet[:tasks]
37       add_object_type('Task', <<-PUPPET, loader)
38         {
39           attributes => {
40             # Fully qualified name of the task
41             name => { type => Pattern[/\\A[a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)*\\z/] },
42 
43             # List of file references referenced by metadata and their paths on disk.
44             # If there are no implementations listed in metadata, the first file is always
45             # the task executable.
46             files => { type => Array[Struct[name => String, path => String]] },
47 
48             # Task metadata
49             metadata => { type => Hash[String, Any] },
50 
51             # Map parameter names to their parsed data type
52             parameters => { type => Optional[Hash[Pattern[/\\A[a-z][a-z0-9_]*\\z/], Type]], value => undef },
53           }
54         }
55       PUPPET
56     end
57   end
register_aliases(aliases, name_authority = RUNTIME_NAME_AUTHORITY, loader = Loaders.loaders.private_environment_loader) click to toggle source
    # File lib/puppet/pops/pcore.rb
129 def self.register_aliases(aliases, name_authority = RUNTIME_NAME_AUTHORITY, loader = Loaders.loaders.private_environment_loader)
130   aliases.each do |name, type_string|
131     add_type(Types::PTypeAliasType.new(name, Types::TypeFactory.type_reference(type_string), nil), loader, name_authority)
132   end
133   aliases.each_key.map { |name| loader.load(:type, name).resolve(loader) }
134 end
register_implementations(impls, name_authority = RUNTIME_NAME_AUTHORITY) click to toggle source
    # File lib/puppet/pops/pcore.rb
125 def self.register_implementations(impls, name_authority = RUNTIME_NAME_AUTHORITY)
126   Loaders.loaders.register_implementations(impls, name_authority)
127 end