Class: Puppet::Pops::Types::ImplementationRegistry Private
- Defined in:
- lib/puppet/pops/types/implementation_registry.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The ImplementationRegistry maps names types in the Puppet Type System to names of corresponding implementation modules/classes. Each mapping is unique and bidirectional so that for any given type name there is only one implementation and vice versa.
Constant Summary collapse
- TYPE_REGEXP_SUBST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
TypeFactory.tuple([PRegexpType::DEFAULT, PStringType::NON_EMPTY])
Instance Method Summary collapse
-
#initialize(parent = nil) ⇒ ImplementationRegistry
constructor
private
Create a new instance.
-
#module_for_type(type) ⇒ Module?
private
Find the module that corresponds to the given type or type name.
-
#module_name_for_type(type) ⇒ String?
private
Find the name for the module that corresponds to the given type or type name.
-
#register_implementation(type, impl_module, _ = nil) ⇒ Object
private
Register a bidirectional mapping between a type and an implementation.
-
#register_implementation_namespace(type_namespace, impl_namespace, _ = nil) ⇒ Object
private
Register a bidirectional namespace mapping.
-
#register_implementation_regexp(type_name_subst, impl_name_subst, _ = nil) ⇒ Object
private
Register a bidirectional regexp mapping.
-
#register_type_mapping(runtime_type, puppet_type_or_pattern, _ = nil) ⇒ Object
private
Register a bidirectional type mapping.
-
#type_for_module(impl_module) ⇒ PAnyType?
private
Find the name for, and then load, the type that corresponds to the given runtime module or module name The method will return ‘nil` if no mapping is found, a TypeReference if a mapping was found but the loader didn’t find the type, or the loaded type.
-
#type_name_for_module(impl_module) ⇒ String?
private
Find the type name and loader that corresponds to the given runtime module or module name.
Constructor Details
#initialize(parent = nil) ⇒ ImplementationRegistry
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 a new instance. This method is normally only called once
15 16 17 18 19 20 21 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 15 def initialize(parent = nil) @parent = parent @type_names_per_implementation = {} @implementations_per_type_name = {} @type_name_substitutions = [] @impl_name_substitutions = [] end |
Instance Method Details
#module_for_type(type) ⇒ Module?
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.
Find the module that corresponds to the given type or type name
90 91 92 93 94 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 90 def module_for_type(type) name = module_name_for_type(type) # TODO Shouldn't ClassLoader be module specific? name.nil? ? nil : ClassLoader.provide(name) end |
#module_name_for_type(type) ⇒ String?
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.
Find the name for the module that corresponds to the given type or type name
80 81 82 83 84 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 80 def module_name_for_type(type) type = type.name if type.is_a?(PAnyType) name = @parent.module_name_for_type(type) unless @parent.nil? name.nil? ? find_mapping(type, @implementations_per_type_name, @type_name_substitutions) : name end |
#register_implementation(type, impl_module, _ = nil) ⇒ Object
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.
Register a bidirectional mapping between a type and an implementation
68 69 70 71 72 73 74 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 68 def register_implementation(type, impl_module, _ = nil) type = type.name if type.is_a?(PAnyType) impl_module = impl_module.name if impl_module.is_a?(Module) @type_names_per_implementation[impl_module] = type @implementations_per_type_name[type] = impl_module nil end |
#register_implementation_namespace(type_namespace, impl_namespace, _ = nil) ⇒ Object
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.
Register a bidirectional namespace mapping
47 48 49 50 51 52 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 47 def register_implementation_namespace(type_namespace, impl_namespace, _ = nil) ns = TypeFormatter::NAME_SEGMENT_SEPARATOR register_implementation_regexp( [/\A#{type_namespace}#{ns}(\w+)\z/, "#{impl_namespace}#{ns}\\1"], [/\A#{impl_namespace}#{ns}(\w+)\z/, "#{type_namespace}#{ns}\\1"]) end |
#register_implementation_regexp(type_name_subst, impl_name_subst, _ = nil) ⇒ Object
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.
Register a bidirectional regexp mapping
58 59 60 61 62 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 58 def register_implementation_regexp(type_name_subst, impl_name_subst, _ = nil) @type_name_substitutions << type_name_subst @impl_name_substitutions << impl_name_subst nil end |
#register_type_mapping(runtime_type, puppet_type) ⇒ Object #register_type_mapping(runtime_type, pattern_replacement) ⇒ Object
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.
Register a bidirectional type mapping.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 31 def register_type_mapping(runtime_type, puppet_type_or_pattern, _ = nil) TypeAsserter.assert_assignable('First argument of type mapping', PRuntimeType::RUBY, runtime_type) expr = runtime_type.name_or_pattern if expr.is_a?(Array) TypeAsserter.assert_instance_of('Second argument of type mapping', TYPE_REGEXP_SUBST, puppet_type_or_pattern) register_implementation_regexp(puppet_type_or_pattern, expr) else TypeAsserter.assert_instance_of('Second argument of type mapping', PTypeType::DEFAULT, puppet_type_or_pattern) register_implementation(puppet_type_or_pattern, expr) end end |
#type_for_module(impl_module) ⇒ PAnyType?
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.
Find the name for, and then load, the type that corresponds to the given runtime module or module name The method will return ‘nil` if no mapping is found, a TypeReference if a mapping was found but the loader didn’t find the type, or the loaded type.
112 113 114 115 116 117 118 119 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 112 def type_for_module(impl_module) name = type_name_for_module(impl_module) if name.nil? nil else TypeParser.singleton.parse(name) end end |
#type_name_for_module(impl_module) ⇒ String?
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.
Find the type name and loader that corresponds to the given runtime module or module name
100 101 102 103 104 |
# File 'lib/puppet/pops/types/implementation_registry.rb', line 100 def type_name_for_module(impl_module) impl_module = impl_module.name if impl_module.is_a?(Module) name = @parent.type_name_for_module(impl_module) unless @parent.nil? name.nil? ? find_mapping(impl_module, @type_names_per_implementation, @impl_name_substitutions) : name end |