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