Module: Puppet::Pops::Pcore
- Includes:
- Types::PuppetObject
- Defined in:
- lib/puppet/pops/pcore.rb
Constant Summary collapse
- TYPE_URI_RX =
Types::TypeFactory.regexp(URI.regexp)
- TYPE_URI =
Types::TypeFactory.pattern(TYPE_URI_RX)
- TYPE_URI_ALIAS =
Types::PTypeAliasType.new('Pcore::URI', nil, TYPE_URI)
- TYPE_SIMPLE_TYPE_NAME =
Types::TypeFactory.pattern(/\A[A-Z]\w*\z/)
- TYPE_QUALIFIED_REFERENCE =
Types::TypeFactory.pattern(/\A[A-Z][\w]*(?:::[A-Z][\w]*)*\z/)
- TYPE_MEMBER_NAME =
Types::PPatternType.new([Types::PRegexpType.new(Patterns::PARAM_NAME)])
- KEY_PCORE_URI =
'pcore_uri'.freeze
- KEY_PCORE_VERSION =
'pcore_version'.freeze
- PCORE_URI =
'http://puppet.com/2016.1/pcore'- PCORE_VERSION =
SemanticPuppet::Version.new(1,0,0)
- PARSABLE_PCORE_VERSIONS =
SemanticPuppet::VersionRange.parse('1.x')
- RUNTIME_NAME_AUTHORITY =
'http://puppet.com/2016.1/runtime'
Class Method Summary collapse
- ._pcore_type ⇒ Object
- .add_alias(name, type, loader, name_authority = RUNTIME_NAME_AUTHORITY) ⇒ Object
- .add_object_type(name, body, loader) ⇒ Object
- .add_type(type, loader, name_authority = RUNTIME_NAME_AUTHORITY) ⇒ Object
- .annotate(instance, annotations_hash) ⇒ Object
-
.create_object_type(loader, ir, impl_class, type_name, parent_name, attributes_hash = EMPTY_HASH, functions_hash = EMPTY_HASH, equality = nil) ⇒ PObjectType
private
Create and register a new ‘Object` type in the Puppet Type System and map it to an implementation class.
- .init(loader, ir) ⇒ Object
- .init_env(loader) ⇒ Object
- .register_aliases(aliases, name_authority = RUNTIME_NAME_AUTHORITY, loader = Loaders.loaders.private_environment_loader) ⇒ Object
- .register_implementations(impls, name_authority = RUNTIME_NAME_AUTHORITY) ⇒ Object
Methods included from Types::PuppetObject
#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type, #to_s
Class Method Details
._pcore_type ⇒ Object
23 24 25 |
# File 'lib/puppet/pops/pcore.rb', line 23 def self._pcore_type @type end |
.add_alias(name, type, loader, name_authority = RUNTIME_NAME_AUTHORITY) ⇒ Object
138 139 140 |
# File 'lib/puppet/pops/pcore.rb', line 138 def self.add_alias(name, type, loader, = RUNTIME_NAME_AUTHORITY) add_type(Types::PTypeAliasType.new(name, nil, type), loader, ) end |
.add_object_type(name, body, loader) ⇒ Object
134 135 136 |
# File 'lib/puppet/pops/pcore.rb', line 134 def self.add_object_type(name, body, loader) add_type(Types::PObjectType.new(name, Parser::EvaluatingParser.new.parse_string(body).body), loader) end |
.add_type(type, loader, name_authority = RUNTIME_NAME_AUTHORITY) ⇒ Object
142 143 144 145 |
# File 'lib/puppet/pops/pcore.rb', line 142 def self.add_type(type, loader, = RUNTIME_NAME_AUTHORITY) loader.set_entry(Loader::TypedName.new(:type, type.name, ), type) type end |
.annotate(instance, annotations_hash) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/puppet/pops/pcore.rb', line 27 def self.annotate(instance, annotations_hash) annotations_hash.each_pair do |type, init_hash| type.implementation_class.annotate(instance) { init_hash } end instance end |
.create_object_type(loader, ir, impl_class, type_name, parent_name, attributes_hash = EMPTY_HASH, functions_hash = EMPTY_HASH, equality = nil) ⇒ PObjectType
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.
Create and register a new ‘Object` type in the Puppet Type System and map it to an implementation class
124 125 126 127 128 129 130 131 132 |
# File 'lib/puppet/pops/pcore.rb', line 124 def self.create_object_type(loader, ir, impl_class, type_name, parent_name, attributes_hash = EMPTY_HASH, functions_hash = EMPTY_HASH, equality = nil) init_hash = {} init_hash[Types::KEY_PARENT] = Types::PTypeReferenceType.new(parent_name) unless parent_name.nil? init_hash[Types::KEY_ATTRIBUTES] = attributes_hash unless attributes_hash.empty? init_hash[Types::KEY_FUNCTIONS] = functions_hash unless functions_hash.empty? init_hash[Types::KEY_EQUALITY] = equality unless equality.nil? ir.register_implementation(type_name, impl_class) add_type(Types::PObjectType.new(type_name, init_hash), loader) end |
.init(loader, ir) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/puppet/pops/pcore.rb', line 81 def self.init(loader, ir) add_alias('Pcore::URI_RX', TYPE_URI_RX, loader) add_type(TYPE_URI_ALIAS, loader) add_alias('Pcore::SimpleTypeName', TYPE_SIMPLE_TYPE_NAME, loader) add_alias('Pcore::MemberName', TYPE_MEMBER_NAME, loader) add_alias('Pcore::TypeName', TYPE_QUALIFIED_REFERENCE, loader) add_alias('Pcore::QRef', TYPE_QUALIFIED_REFERENCE, loader) Types::TypedModelObject.register_ptypes(loader, ir) @type = create_object_type(loader, ir, Pcore, 'Pcore', nil) ir.register_implementation_namespace('Pcore', 'Puppet::Pops::Pcore') ir.register_implementation_namespace('Puppet::AST', 'Puppet::Pops::Model') ir.register_implementation('Puppet::AST::Locator', 'Puppet::Pops::Parser::Locator::Locator19') Resource.register_ptypes(loader, ir) Lookup::Context.register_ptype(loader, ir); Lookup::DataProvider.register_types(loader) add_object_type('Deferred', " {\n attributes => {\n # Fully qualified name of the function\n name => { type => Pattern[/\\\\A[$]?[a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)*\\\\z/] },\n arguments => { type => Optional[Array[Any]], value => undef},\n }\n }\n PUPPET\n\nend\n", loader) |
.init_env(loader) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/puppet/pops/pcore.rb', line 34 def self.init_env(loader) if Puppet[:tasks] add_object_type('Task', " {\n attributes => {\n # Fully qualified name of the task\n name => { type => Pattern[/\\\\A[a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)*\\\\z/] },\n\n # List of implementations with requirements\n implementations => { type => Array[Struct[name => String, path => String, Optional[requirements] => Array[String]], 1] },\n\n # Task description\n description => { type => Optional[String], value => undef },\n\n # Puppet Task version\n puppet_task_version => { type => Integer, value => 1 },\n\n # Type, description, and sensitive property of each parameter\n parameters => {\n type => Optional[Hash[\n Pattern[/\\\\A[a-z][a-z0-9_]*\\\\z/],\n Struct[\n Optional[description] => String,\n Optional[sensitive] => Boolean,\n type => Type]]],\n value => undef\n },\n\n # Type, description, and sensitive property of each output\n output => {\n type => Optional[Hash[\n Pattern[/\\\\A[a-z][a-z0-9_]*\\\\z/],\n Struct[\n Optional[description] => String,\n Optional[sensitive] => Boolean,\n type => Type]]],\n value => undef\n },\n\n supports_noop => { type => Boolean, value => false },\n input_method => { type => Optional[String] },\n }\n }\n PUPPET\n end\nend\n", loader) |
.register_aliases(aliases, name_authority = RUNTIME_NAME_AUTHORITY, loader = Loaders.loaders.private_environment_loader) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/puppet/pops/pcore.rb', line 151 def self.register_aliases(aliases, = RUNTIME_NAME_AUTHORITY, loader = Loaders.loaders.private_environment_loader) aliases.each do |name, type_string| add_type(Types::PTypeAliasType.new(name, Types::TypeFactory.type_reference(type_string), nil), loader, ) end aliases.each_key.map { |name| loader.load(:type, name).resolve(loader) } end |
.register_implementations(impls, name_authority = RUNTIME_NAME_AUTHORITY) ⇒ Object
147 148 149 |
# File 'lib/puppet/pops/pcore.rb', line 147 def self.register_implementations(impls, = RUNTIME_NAME_AUTHORITY) Loaders.loaders.register_implementations(impls, ) end |