class Puppet::Pops::Types::PObjectType

@api public

Constants

ATTRIBUTE_KIND_CONSTANT
ATTRIBUTE_KIND_DERIVED
ATTRIBUTE_KIND_GIVEN_OR_DERIVED
ATTRIBUTE_KIND_REFERENCE
DEFAULT
TYPE_ATTRIBUTE
TYPE_ATTRIBUTES
TYPE_ATTRIBUTE_CALLABLE
TYPE_ATTRIBUTE_KIND
TYPE_CHECKS
TYPE_CONSTANTS
TYPE_EQUALITY
TYPE_FUNCTION
TYPE_FUNCTIONS
TYPE_FUNCTION_TYPE
TYPE_OBJECT_I12N
TYPE_OBJECT_NAME
TYPE_PARAMETER
TYPE_PARAMETERS

Attributes

annotations[R]
checks[R]
equality[R]
name[R]
parent[R]

Public Class Methods

from_hash(hash) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
665 def self.from_hash(hash)
666   new(hash, nil)
667 end
impl_class() click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
507 def self.impl_class
508   @impl_class
509 end
new(_pcore_init_hash, init_hash_expression = nil) click to toggle source

Initialize an Object Type instance. The initialization will use either a name and an initialization hash expression, or a fully resolved initialization hash.

@overload initialize(name, init_hash_expression)

Used when the Object type is loaded using a type alias expression. When that happens, it is important that
the actual resolution of the expression is deferred until all definitions have been made known to the current
loader. The object will then be resolved when it is loaded by the {TypeParser}. "resolved" here, means that
the hash expression is fully resolved, and then passed to the {#_pcore_init_from_hash} method.
@param name [String] The name of the object
@param init_hash_expression [Model::LiteralHash] The hash describing the Object features

@overload initialize(init_hash)

Used when the object is created by the {TypeFactory}. The init_hash must be fully resolved.
@param _pcore_init_hash [Hash{String=>Object}] The hash describing the Object features
@param loader [Loaders::Loader,nil] the loader that loaded the type

@api private

    # File lib/puppet/pops/types/p_object_type.rb
427 def initialize(_pcore_init_hash, init_hash_expression = nil)
428   if _pcore_init_hash.is_a?(Hash)
429     _pcore_init_from_hash(_pcore_init_hash)
430     @loader = init_hash_expression unless init_hash_expression.nil?
431   else
432     @type_parameters = EMPTY_HASH
433     @attributes = EMPTY_HASH
434     @functions = EMPTY_HASH
435     @name = TypeAsserter.assert_instance_of('object name', TYPE_OBJECT_NAME, _pcore_init_hash)
436     @init_hash_expression = init_hash_expression
437   end
438 end
register_ptype(loader, ir) click to toggle source
   # File lib/puppet/pops/types/p_object_type.rb
78 def self.register_ptype(loader, ir)
79   type = create_ptype(loader, ir, 'AnyType', '_pcore_init_hash' => TYPE_OBJECT_I12N)
80 
81   # Now, when the Object type exists, add annotations with keys derived from Annotation and freeze the types.
82   annotations = TypeFactory.optional(PHashType.new(PTypeType.new(Annotation._pcore_type), TypeFactory.hash_kv(Pcore::TYPE_MEMBER_NAME, PAnyType::DEFAULT)))
83   TYPE_ATTRIBUTE.hashed_elements[KEY_ANNOTATIONS].replace_value_type(annotations)
84   TYPE_FUNCTION.hashed_elements[KEY_ANNOTATIONS].replace_value_type(annotations)
85   TYPE_OBJECT_I12N.hashed_elements[KEY_ANNOTATIONS].replace_value_type(annotations)
86   PTypeSetType::TYPE_TYPESET_I12N.hashed_elements[KEY_ANNOTATIONS].replace_value_type(annotations)
87   PTypeSetType::TYPE_TYPE_REFERENCE_I12N.hashed_elements[KEY_ANNOTATIONS].replace_value_type(annotations)
88   type
89 end

Public Instance Methods

[](name) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
807 def [](name)
808   member = @attributes[name] || @functions[name]
809   if member.nil?
810     rp = resolved_parent
811     member = rp[name] if rp.is_a?(PObjectType)
812   end
813   member
814 end
_pcore_init_from_hash(init_hash) click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
670 def _pcore_init_from_hash(init_hash)
671   TypeAsserter.assert_instance_of('object initializer', TYPE_OBJECT_I12N, init_hash)
672   @type_parameters = EMPTY_HASH
673   @attributes = EMPTY_HASH
674   @functions = EMPTY_HASH
675 
676   # Name given to the loader have higher precedence than a name declared in the type
677   @name ||= init_hash[KEY_NAME]
678   @name.freeze unless @name.nil?
679 
680   @parent = init_hash[KEY_PARENT]
681 
682   parent_members = EMPTY_HASH
683   parent_type_params = EMPTY_HASH
684   parent_object_type = nil
685   unless @parent.nil?
686     check_self_recursion(self)
687     rp = resolved_parent
688     raise Puppet::ParseError, _("reference to unresolved type '%{name}'") % { :name => rp.type_string } if rp.is_a?(PTypeReferenceType)
689     if rp.is_a?(PObjectType)
690       parent_object_type = rp
691       parent_members = rp.members(true)
692       parent_type_params = rp.type_parameters(true)
693     end
694   end
695 
696   type_parameters = init_hash[KEY_TYPE_PARAMETERS]
697   unless type_parameters.nil? || type_parameters.empty?
698     @type_parameters = {}
699     type_parameters.each do |key, param_spec|
700       param_value = :undef
701       if param_spec.is_a?(Hash)
702         param_type = param_spec[KEY_TYPE]
703         param_value = param_spec[KEY_VALUE] if param_spec.include?(KEY_VALUE)
704       else
705         param_type = TypeAsserter.assert_instance_of(nil, PTypeType::DEFAULT, param_spec) { "type_parameter #{label}[#{key}]" }
706       end
707       param_type = POptionalType.new(param_type) unless param_type.is_a?(POptionalType)
708       type_param = PTypeParameter.new(key, self, KEY_TYPE => param_type, KEY_VALUE => param_value).assert_override(parent_type_params)
709       @type_parameters[key] = type_param
710     end
711   end
712 
713   constants = init_hash[KEY_CONSTANTS]
714   attr_specs = init_hash[KEY_ATTRIBUTES]
715   if attr_specs.nil?
716     attr_specs = {}
717   else
718     # attr_specs might be frozen
719     attr_specs = Hash[attr_specs]
720   end
721   unless constants.nil? || constants.empty?
722     constants.each do |key, value|
723       if attr_specs.include?(key)
724         raise Puppet::ParseError, _("attribute %{label}[%{key}] is defined as both a constant and an attribute") % { label: label, key: key }
725       end
726       attr_spec = {
727         # Type must be generic here, or overrides would become impossible
728         KEY_TYPE => TypeCalculator.infer(value).generalize,
729         KEY_VALUE => value,
730         KEY_KIND => ATTRIBUTE_KIND_CONSTANT
731       }
732       # Indicate override if parent member exists. Type check etc. will take place later on.
733       attr_spec[KEY_OVERRIDE] = parent_members.include?(key)
734       attr_specs[key] = attr_spec
735     end
736   end
737 
738   unless attr_specs.empty?
739     @attributes = Hash[attr_specs.map do |key, attr_spec|
740       unless attr_spec.is_a?(Hash)
741         attr_type = TypeAsserter.assert_instance_of(nil, PTypeType::DEFAULT, attr_spec) { "attribute #{label}[#{key}]" }
742         attr_spec = { KEY_TYPE => attr_type }
743         attr_spec[KEY_VALUE] = nil if attr_type.is_a?(POptionalType)
744       end
745       attr = PAttribute.new(key, self, attr_spec)
746       [attr.name, attr.assert_override(parent_members)]
747     end].freeze
748   end
749 
750   func_specs = init_hash[KEY_FUNCTIONS]
751   unless func_specs.nil? || func_specs.empty?
752     @functions = Hash[func_specs.map do |key, func_spec|
753       func_spec = { KEY_TYPE => TypeAsserter.assert_instance_of(nil, TYPE_FUNCTION_TYPE, func_spec) { "function #{label}[#{key}]" } } unless func_spec.is_a?(Hash)
754       func = PFunction.new(key, self, func_spec)
755       name = func.name
756       raise Puppet::ParseError, _("%{label} conflicts with attribute with the same name") % { label: func.label } if @attributes.include?(name)
757       [name, func.assert_override(parent_members)]
758     end].freeze
759   end
760 
761   @equality_include_type = init_hash[KEY_EQUALITY_INCLUDE_TYPE]
762   @equality_include_type = true if @equality_include_type.nil?
763 
764   equality = init_hash[KEY_EQUALITY]
765   equality = [equality] if equality.is_a?(String)
766   if equality.is_a?(Array)
767     unless equality.empty?
768       #TRANSLATORS equality_include_type = false should not be translated
769       raise Puppet::ParseError, _('equality_include_type = false cannot be combined with non empty equality specification') unless @equality_include_type
770       parent_eq_attrs = nil
771       equality.each do |attr_name|
772 
773         attr = parent_members[attr_name]
774         if attr.nil?
775           attr = @attributes[attr_name] || @functions[attr_name]
776         elsif attr.is_a?(PAttribute)
777           # Assert that attribute is not already include by parent equality
778           parent_eq_attrs ||= parent_object_type.equality_attributes
779           if parent_eq_attrs.include?(attr_name)
780             including_parent = find_equality_definer_of(attr)
781             raise Puppet::ParseError, _("%{label} equality is referencing %{attribute} which is included in equality of %{including_parent}") %
782                 { label: label, attribute: attr.label, including_parent: including_parent.label }
783           end
784         end
785 
786         unless attr.is_a?(PAttribute)
787           if attr.nil?
788             raise Puppet::ParseError, _("%{label} equality is referencing non existent attribute '%{attribute}'") % { label: label, attribute: attr_name }
789           end
790           raise Puppet::ParseError, _("%{label} equality is referencing %{attribute}. Only attribute references are allowed") %
791               { label: label, attribute: attr.label }
792         end
793         if attr.kind == ATTRIBUTE_KIND_CONSTANT
794           raise Puppet::ParseError, _("%{label} equality is referencing constant %{attribute}.") % { label: label, attribute: attr.label } + ' ' +
795               _("Reference to constant is not allowed in equality")
796         end
797       end
798     end
799     equality.freeze
800   end
801   @equality = equality
802 
803   @checks = init_hash[KEY_CHECKS]
804   init_annotatable(init_hash)
805 end
_pcore_init_hash(include_name = true) click to toggle source

The init_hash is primarily intended for serialization and string representation purposes. It creates a hash suitable for passing to {PObjectType#new(init_hash)}

@return [Hash{String=>Object}] the features hash @api public

Calls superclass method Puppet::Pops::Types::Annotatable#_pcore_init_hash
    # File lib/puppet/pops/types/p_object_type.rb
873 def _pcore_init_hash(include_name = true)
874   result = super()
875   result[KEY_NAME] = @name if include_name && !@name.nil?
876   result[KEY_PARENT] = @parent unless @parent.nil?
877   result[KEY_TYPE_PARAMETERS] = compressed_members_hash(@type_parameters) unless @type_parameters.empty?
878   unless @attributes.empty?
879     # Divide attributes into constants and others
880     tc = TypeCalculator.singleton
881     constants, others = @attributes.partition do |_, a|
882       a.kind == ATTRIBUTE_KIND_CONSTANT && a.type == tc.infer(a.value).generalize
883     end.map { |ha| Hash[ha] }
884 
885     result[KEY_ATTRIBUTES] = compressed_members_hash(others) unless others.empty?
886     unless constants.empty?
887       # { kind => 'constant', type => <type of value>, value => <value> } becomes just <value>
888       constants.each_pair { |key, a| constants[key] = a.value }
889       result[KEY_CONSTANTS] = constants
890     end
891   end
892   result[KEY_FUNCTIONS] = compressed_members_hash(@functions) unless @functions.empty?
893   result[KEY_EQUALITY] = @equality unless @equality.nil?
894   result[KEY_CHECKS] = @checks unless @checks.nil?
895   result
896 end
accept(visitor, guard) click to toggle source
Calls superclass method Puppet::Pops::Types::PMetaType#accept
    # File lib/puppet/pops/types/p_object_type.rb
816 def accept(visitor, guard)
817   guarded_recursion(guard, nil) do |g|
818     super(visitor, g)
819     @parent.accept(visitor, g) unless parent.nil?
820     @type_parameters.values.each { |p| p.accept(visitor, g) }
821     @attributes.values.each { |a| a.accept(visitor, g) }
822     @functions.values.each { |f| f.accept(visitor, g) }
823   end
824 end
allocate() click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
838 def allocate
839   implementation_class.allocate
840 end
attr_reader_name(se) click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
657 def attr_reader_name(se)
658   if se.value_type.is_a?(PBooleanType) || se.value_type.is_a?(POptionalType) && se.value_type.type.is_a?(PBooleanType)
659     "#{se.name}?"
660   else
661     se.name
662   end
663 end
attributes(include_parent = false) click to toggle source

Returns the attributes of this `Object` type. If include_parent is `true`, then all inherited attributes will be included in the returned `Hash`.

@param include_parent [Boolean] `true` if inherited attributes should be included @return [Hash{String=>PAttribute}] a hash with the attributes @api public

    # File lib/puppet/pops/types/p_object_type.rb
949 def attributes(include_parent = false)
950   get_members(include_parent, :attributes)
951 end
callable_args?(callable, guard) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
826 def callable_args?(callable, guard)
827   @parent.nil? ? false : @parent.callable_args?(callable, guard)
828 end
check_self_recursion(originator) click to toggle source

Assert that this type does not inherit from itself @api private

    # File lib/puppet/pops/types/p_object_type.rb
982 def check_self_recursion(originator)
983   unless @parent.nil?
984     raise Puppet::Error, "The Object type '#{originator.label}' inherits from itself" if @parent.equal?(originator)
985     @parent.check_self_recursion(originator)
986   end
987 end
create(*args) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
525 def create(*args)
526   self.class.impl_class.from_asserted_args(*args)
527 end
create_init_hash_type() click to toggle source

Creates the type that a initialization hash used for creating instances of this type must conform to.

@return [PStructType] the initialization hash type @api private

    # File lib/puppet/pops/types/p_object_type.rb
854 def create_init_hash_type
855   struct_elems = {}
856   attributes(true).values.each do |attr|
857     unless attr.kind == ATTRIBUTE_KIND_CONSTANT || attr.kind == ATTRIBUTE_KIND_DERIVED
858       if attr.value?
859         struct_elems[TypeFactory.optional(attr.name)] = attr.type
860       else
861         struct_elems[attr.name] = attr.type
862       end
863     end
864   end
865   TypeFactory.struct(struct_elems)
866 end
create_new_function() click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
489 def create_new_function
490   impl_class = implementation_class
491   return impl_class.create_new_function(self) if impl_class.respond_to?(:create_new_function)
492 
493   (param_names, param_types, required_param_count) = parameter_info(impl_class)
494 
495   # Create the callable with a size that reflects the required and optional parameters
496   create_type = TypeFactory.callable(*param_types, required_param_count, param_names.size)
497   from_hash_type = TypeFactory.callable(init_hash_type, 1, 1)
498 
499   # Create and return a #new_XXX function where the dispatchers are added programmatically.
500   Puppet::Functions.create_loaded_function(:"new_#{name}", loader) do
501 
502     # The class that creates new instances must be available to the constructor methods
503     # and is therefore declared as a variable and accessor on the class that represents
504     # this added function.
505     @impl_class = impl_class
506 
507     def self.impl_class
508       @impl_class
509     end
510 
511     # It's recommended that an implementor of an Object type provides the method #from_asserted_hash.
512     # This method should accept a hash and assume that type assertion has been made already (it is made
513     # by the dispatch added here).
514     if impl_class.respond_to?(:from_asserted_hash)
515       dispatcher.add(Functions::Dispatch.new(from_hash_type, :from_hash, ['hash']))
516       def from_hash(hash)
517         self.class.impl_class.from_asserted_hash(hash)
518       end
519     end
520 
521     # Add the dispatch that uses the standard #from_asserted_args or #new method on the class. It's assumed that the
522     # method performs no assertions.
523     dispatcher.add(Functions::Dispatch.new(create_type, :create, param_names))
524     if impl_class.respond_to?(:from_asserted_args)
525       def create(*args)
526         self.class.impl_class.from_asserted_args(*args)
527       end
528     else
529       def create(*args)
530         self.class.impl_class.new(*args)
531       end
532     end
533   end
534 end
eql?(o) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
898 def eql?(o)
899   self.class == o.class &&
900     @name == o.name &&
901     @parent == o.parent &&
902     @type_parameters == o.type_parameters &&
903     @attributes == o.attributes &&
904     @functions == o.functions &&
905     @equality == o.equality &&
906     @checks == o.checks
907 end
equality_attributes() click to toggle source

Returns the attributes that participate in equality comparison. Inherited equality attributes are included. @return [Hash{String=>PAttribute}] a hash of attributes @api public

    # File lib/puppet/pops/types/p_object_type.rb
957 def equality_attributes
958   all = {}
959   collect_equality_attributes(all)
960   all
961 end
equality_include_type?() click to toggle source

@return [Boolean] `true` if this type is included when comparing instances @api public

    # File lib/puppet/pops/types/p_object_type.rb
965 def equality_include_type?
966   @equality_include_type
967 end
extract_init_hash(o) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
579 def extract_init_hash(o)
580   return o._pcore_init_hash if o.respond_to?(:_pcore_init_hash)
581 
582   result = {}
583   pic = parameter_info(o.class)
584   attrs = attributes(true)
585   pic[0].each do |name|
586     v = o.send(name)
587     result[name] = v unless attrs[name].default_value?(v)
588   end
589   result
590 end
from_hash(hash) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
516 def from_hash(hash)
517   self.class.impl_class.from_asserted_hash(hash)
518 end
functions(include_parent = false) click to toggle source

Returns the functions of this `Object` type. If include_parent is `true`, then all inherited functions will be included in the returned `Hash`.

@param include_parent [Boolean] `true` if inherited functions should be included @return [Hash{String=>PFunction}] a hash with the functions @api public

    # File lib/puppet/pops/types/p_object_type.rb
975 def functions(include_parent = false)
976   get_members(include_parent, :functions)
977 end
hash() click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
909 def hash
910   @name.nil? ? [@parent, @type_parameters, @attributes, @functions].hash : @name.hash
911 end
implementation_class(create = true) click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
537 def implementation_class(create = true)
538   if @implementation_class.nil? && create
539     ir = Loaders.implementation_registry
540     class_name = ir.nil? ? nil : ir.module_name_for_type(self)
541     if class_name.nil?
542       # Use generator to create a default implementation
543       @implementation_class = RubyGenerator.new.create_class(self)
544       @implementation_class.class_eval(&@implementation_override) if instance_variable_defined?(:@implementation_override)
545     else
546       # Can the mapping be loaded?
547       @implementation_class = ClassLoader.provide(class_name)
548 
549       raise Puppet::Error, "Unable to load class #{class_name}" if @implementation_class.nil?
550       unless @implementation_class < PuppetObject || @implementation_class.respond_to?(:ecore)
551         raise Puppet::Error, "Unable to create an instance of #{name}. #{class_name} does not include module #{PuppetObject.name}"
552       end
553     end
554   end
555   @implementation_class
556 end
implementation_class=(cls) click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
559 def implementation_class=(cls)
560   raise ArgumentError, "attempt to redefine implementation class for #{label}" unless @implementation_class.nil?
561   @implementation_class = cls
562 end
implementation_override=(block) click to toggle source

The block passed to this method will be passed in a call to `#class_eval` on the dynamically generated class for this data type. It's indended use is to complement or redefine the generated methods and attribute readers.

The method is normally called with the block passed to `#implementation` when a data type is defined using {Puppet::DataTypes::create_type}.

@api private

    # File lib/puppet/pops/types/p_object_type.rb
572 def implementation_override=(block)
573   if !@implementation_class.nil? || instance_variable_defined?(:@implementation_override)
574     raise ArgumentError, "attempt to redefine implementation override for #{label}"
575   end
576   @implementation_override = block
577 end
init_hash_type() click to toggle source

Returns the type that a initialization hash used for creating instances of this type must conform to.

@return [PStructType] the initialization hash type @api public

    # File lib/puppet/pops/types/p_object_type.rb
834 def init_hash_type
835   @init_hash_type ||= create_init_hash_type
836 end
instance?(o, guard = nil) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
440 def instance?(o, guard = nil)
441   if o.is_a?(PuppetObject)
442     assignable?(o._pcore_type, guard)
443   else
444     name = o.class.name
445     return false if name.nil? # anonymous class that doesn't implement PuppetObject is not an instance
446     ir = Loaders.implementation_registry
447     type = ir.nil? ? nil : ir.type_for_module(name)
448     !type.nil? && assignable?(type, guard)
449   end
450 end
iterable?(guard = nil) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
917 def iterable?(guard = nil)
918   @parent.nil? ? false : @parent.iterable?(guard)
919 end
iterable_type(guard = nil) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
921 def iterable_type(guard = nil)
922   @parent.nil? ? false : @parent.iterable_type(guard)
923 end
kind_of_callable?(optional=true, guard = nil) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
913 def kind_of_callable?(optional=true, guard = nil)
914   @parent.nil? ? false : @parent.kind_of_callable?(optional, guard)
915 end
label() click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
990 def label
991   @name || 'Object'
992 end
members(include_parent = false) click to toggle source

Returns the members (attributes and functions) of this `Object` type. If include_parent is `true`, then all inherited members will be included in the returned `Hash`.

@param include_parent [Boolean] `true` if inherited members should be included @return [Hash{String=>PAnnotatedMember}] a hash with the members @api public

    # File lib/puppet/pops/types/p_object_type.rb
939 def members(include_parent = false)
940   get_members(include_parent, :both)
941 end
new_function() click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
453 def new_function
454   @new_function ||= create_new_function
455 end
parameter_info(impl_class) click to toggle source

@api private @return [(Array<String>, Array<PAnyType>, Integer)] array of parameter names, array of parameter types, and a count reflecting the required number of parameters

    # File lib/puppet/pops/types/p_object_type.rb
594 def parameter_info(impl_class)
595   # Create a types and a names array where optional entries ends up last
596   @parameter_info ||= {}
597   pic = @parameter_info[impl_class]
598   return pic if pic
599 
600   opt_types = []
601   opt_names = []
602   non_opt_types = []
603   non_opt_names = []
604   init_hash_type.elements.each do |se|
605     if se.key_type.is_a?(POptionalType)
606       opt_names << se.name
607       opt_types << se.value_type
608     else
609       non_opt_names << se.name
610       non_opt_types << se.value_type
611     end
612   end
613   param_names = non_opt_names + opt_names
614   param_types = non_opt_types + opt_types
615   param_count = param_names.size
616 
617   init = impl_class.respond_to?(:from_asserted_args) ? impl_class.method(:from_asserted_args) : impl_class.instance_method(:initialize)
618   init_non_opt_count = 0
619   init_param_names = init.parameters.map do |p|
620     init_non_opt_count += 1 if :req == p[0]
621     n = p[1].to_s
622     r = RubyGenerator.unprotect_reserved_name(n)
623     unless r.equal?(n)
624       # assert that the protected name wasn't a real name (names can start with underscore)
625       n = r unless param_names.index(r).nil?
626     end
627     n
628   end
629 
630   if init_param_names != param_names
631     if init_param_names.size < param_count || init_non_opt_count > param_count
632       raise Serialization::SerializationError, "Initializer for class #{impl_class.name} does not match the attributes of #{name}"
633     end
634     init_param_names = init_param_names[0, param_count] if init_param_names.size > param_count
635     unless init_param_names == param_names
636       # Reorder needed to match initialize method arguments
637       new_param_types = []
638       init_param_names.each do |ip|
639         index = param_names.index(ip)
640         if index.nil?
641           raise Serialization::SerializationError,
642             "Initializer for class #{impl_class.name} parameter '#{ip}' does not match any of the the attributes of type #{name}"
643         end
644         new_param_types << param_types[index]
645       end
646       param_names = init_param_names
647       param_types = new_param_types
648     end
649   end
650 
651   pic = [param_names.freeze, param_types.freeze, non_opt_types.size].freeze
652   @parameter_info[impl_class] = pic
653   pic
654 end
parameterized?() click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
925 def parameterized?
926   if @type_parameters.empty?
927     @parent.is_a?(PObjectType) ? @parent.parameterized? : false
928   else
929     true
930   end
931 end
read(value_count, deserializer) click to toggle source

Read an instance of this type from a deserializer @param [Integer] value_count the number attributes needed to create the instance @param [Serialization::Deserializer] deserializer the deserializer to read from @return [Object] the created instance @api private

    # File lib/puppet/pops/types/p_object_type.rb
476 def read(value_count, deserializer)
477   reader.read(self, implementation_class, value_count, deserializer)
478 end
reader=(reader) click to toggle source

Assign a new instance reader to this type @param [Serialization::InstanceReader] reader the reader to assign @api private

    # File lib/puppet/pops/types/p_object_type.rb
460 def reader=(reader)
461   @reader = reader
462 end
resolved_parent() click to toggle source

@api private

     # File lib/puppet/pops/types/p_object_type.rb
 995 def resolved_parent
 996   parent = @parent
 997   while parent.is_a?(PTypeAliasType)
 998     parent = parent.resolved_type
 999   end
1000   parent
1001 end
simple_name() click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1003 def simple_name
1004   label.split(DOUBLE_COLON).last
1005 end
type_parameters(include_parent = false) click to toggle source

Returns the type_parameters of this `Object` type. If include_parent is `true`, then all inherited type_parameters will be included in the returned `Hash`.

@param include_parent [Boolean] `true` if inherited type_parameters should be included @return [Hash{String=>PTypeParameter}] a hash with the type_parameters @api public

     # File lib/puppet/pops/types/p_object_type.rb
1013 def type_parameters(include_parent = false)
1014   all = {}
1015   collect_type_parameters(all, include_parent)
1016   all
1017 end
write(value, serializer) click to toggle source

Write an instance of this type using a serializer @param [Object] value the instance to write @param [Serialization::Serializer] the serializer to write to @api private

    # File lib/puppet/pops/types/p_object_type.rb
484 def write(value, serializer)
485   writer.write(self, value, serializer)
486 end
writer=(writer) click to toggle source

Assign a new instance write to this type @param [Serialization::InstanceWriter] the writer to assign @api private

    # File lib/puppet/pops/types/p_object_type.rb
467 def writer=(writer)
468   @writer = writer
469 end

Protected Instance Methods

_assignable?(o, guard) click to toggle source

An Object type is only assignable from another Object type. The other type or one of its parents must be equal to this type.

     # File lib/puppet/pops/types/p_object_type.rb
1023 def _assignable?(o, guard)
1024   if o.is_a?(PObjectType)
1025     if DEFAULT == self || self == o
1026       true
1027     else
1028       op = o.parent
1029       op.nil? ? false : assignable?(op, guard)
1030     end
1031   elsif o.is_a?(PObjectTypeExtension)
1032     assignable?(o.base_type, guard)
1033   else
1034     false
1035   end
1036 end
collect_equality_attributes(collector) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1054 def collect_equality_attributes(collector)
1055   parent = resolved_parent
1056   parent.collect_equality_attributes(collector) if parent.is_a?(PObjectType)
1057   if @equality.nil?
1058     # All attributes except constants participate
1059     collector.merge!(@attributes.reject { |_, attr| attr.kind == ATTRIBUTE_KIND_CONSTANT })
1060   else
1061     collector.merge!(Hash[@equality.map { |attr_name| [attr_name, @attributes[attr_name]] }])
1062   end
1063   nil
1064 end
collect_members(collector, include_parent, member_type) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1044 def collect_members(collector, include_parent, member_type)
1045   if include_parent
1046     parent = resolved_parent
1047     parent.collect_members(collector, include_parent, member_type) if parent.is_a?(PObjectType)
1048   end
1049   collector.merge!(@attributes) unless member_type == :functions
1050   collector.merge!(@functions) unless member_type == :attributes
1051   nil
1052 end
collect_type_parameters(collector, include_parent) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1066 def collect_type_parameters(collector, include_parent)
1067   if include_parent
1068     parent = resolved_parent
1069     parent.collect_type_parameters(collector, include_parent) if parent.is_a?(PObjectType)
1070   end
1071   collector.merge!(@type_parameters)
1072   nil
1073 end
get_members(include_parent, member_type) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1038 def get_members(include_parent, member_type)
1039   all = {}
1040   collect_members(all, include_parent, member_type)
1041   all
1042 end

Private Instance Methods

compressed_members_hash(features) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1077 def compressed_members_hash(features)
1078   Hash[features.values.map do |feature|
1079     fh = feature._pcore_init_hash
1080     if fh.size == 1
1081       type = fh[KEY_TYPE]
1082       fh = type unless type.nil?
1083     end
1084     [feature.name, fh]
1085   end]
1086 end
find_equality_definer_of(attr) click to toggle source

@return [PObjectType] the topmost parent who's equality_attributes include the given attr

     # File lib/puppet/pops/types/p_object_type.rb
1089 def find_equality_definer_of(attr)
1090   type = self
1091   while !type.nil? do
1092     p = type.resolved_parent
1093     return type unless p.is_a?(PObjectType)
1094     return type unless p.equality_attributes.include?(attr.name)
1095     type = p
1096   end
1097   nil
1098 end
guarded_recursion(guard, dflt) { |guard| ... } click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1100 def guarded_recursion(guard, dflt)
1101   if @self_recursion
1102     guard ||= RecursionGuard.new
1103     guard.with_this(self) { |state| (state & RecursionGuard::SELF_RECURSION_IN_THIS) == 0 ? yield(guard) : dflt }
1104   else
1105     yield(guard)
1106   end
1107 end
reader() click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1109 def reader
1110   @reader ||= Serialization::ObjectReader::INSTANCE
1111 end
writer() click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1113 def writer
1114   @writer ||= Serialization::ObjectWriter::INSTANCE
1115 end