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

Public Instance Methods

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

@api private

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

@api private

    # File lib/puppet/pops/types/p_object_type.rb
656 def attr_reader_name(se)
657   if se.value_type.is_a?(PBooleanType) || se.value_type.is_a?(POptionalType) && se.value_type.type.is_a?(PBooleanType)
658     "#{se.name}?"
659   else
660     se.name
661   end
662 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
948 def attributes(include_parent = false)
949   get_members(include_parent, :attributes)
950 end
callable_args?(callable, guard) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
825 def callable_args?(callable, guard)
826   @parent.nil? ? false : @parent.callable_args?(callable, guard)
827 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
981 def check_self_recursion(originator)
982   unless @parent.nil?
983     raise Puppet::Error, "The Object type '#{originator.label}' inherits from itself" if @parent.equal?(originator)
984     @parent.check_self_recursion(originator)
985   end
986 end
create(*args) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
524 def create(*args)
525   self.class.impl_class.from_asserted_args(*args)
526 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
853 def create_init_hash_type
854   struct_elems = {}
855   attributes(true).values.each do |attr|
856     unless attr.kind == ATTRIBUTE_KIND_CONSTANT || attr.kind == ATTRIBUTE_KIND_DERIVED
857       if attr.value?
858         struct_elems[TypeFactory.optional(attr.name)] = attr.type
859       else
860         struct_elems[attr.name] = attr.type
861       end
862     end
863   end
864   TypeFactory.struct(struct_elems)
865 end
create_new_function() click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
488 def create_new_function
489   impl_class = implementation_class
490   return impl_class.create_new_function(self) if impl_class.respond_to?(:create_new_function)
491 
492   (param_names, param_types, required_param_count) = parameter_info(impl_class)
493 
494   # Create the callable with a size that reflects the required and optional parameters
495   create_type = TypeFactory.callable(*param_types, required_param_count, param_names.size)
496   from_hash_type = TypeFactory.callable(init_hash_type, 1, 1)
497 
498   # Create and return a #new_XXX function where the dispatchers are added programmatically.
499   Puppet::Functions.create_loaded_function(:"new_#{name}", loader) do
500 
501     # The class that creates new instances must be available to the constructor methods
502     # and is therefore declared as a variable and accessor on the class that represents
503     # this added function.
504     @impl_class = impl_class
505 
506     def self.impl_class
507       @impl_class
508     end
509 
510     # It's recommended that an implementor of an Object type provides the method #from_asserted_hash.
511     # This method should accept a hash and assume that type assertion has been made already (it is made
512     # by the dispatch added here).
513     if impl_class.respond_to?(:from_asserted_hash)
514       dispatcher.add(Functions::Dispatch.new(from_hash_type, :from_hash, ['hash']))
515       def from_hash(hash)
516         self.class.impl_class.from_asserted_hash(hash)
517       end
518     end
519 
520     # Add the dispatch that uses the standard #from_asserted_args or #new method on the class. It's assumed that the
521     # method performs no assertions.
522     dispatcher.add(Functions::Dispatch.new(create_type, :create, param_names))
523     if impl_class.respond_to?(:from_asserted_args)
524       def create(*args)
525         self.class.impl_class.from_asserted_args(*args)
526       end
527     else
528       def create(*args)
529         self.class.impl_class.new(*args)
530       end
531     end
532   end
533 end
eql?(o) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
897 def eql?(o)
898   self.class == o.class &&
899     @name == o.name &&
900     @parent == o.parent &&
901     @type_parameters == o.type_parameters &&
902     @attributes == o.attributes &&
903     @functions == o.functions &&
904     @equality == o.equality &&
905     @checks == o.checks
906 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
956 def equality_attributes
957   all = {}
958   collect_equality_attributes(all)
959   all
960 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
964 def equality_include_type?
965   @equality_include_type
966 end
extract_init_hash(o) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
578 def extract_init_hash(o)
579   return o._pcore_init_hash if o.respond_to?(:_pcore_init_hash)
580 
581   result = {}
582   pic = parameter_info(o.class)
583   attrs = attributes(true)
584   pic[0].each do |name|
585     v = o.send(name)
586     result[name] = v unless attrs[name].default_value?(v)
587   end
588   result
589 end
from_hash(hash) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
515 def from_hash(hash)
516   self.class.impl_class.from_asserted_hash(hash)
517 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
974 def functions(include_parent = false)
975   get_members(include_parent, :functions)
976 end
hash() click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
908 def hash
909   @name.nil? ? [@parent, @type_parameters, @attributes, @functions].hash : @name.hash
910 end
implementation_class(create = true) click to toggle source

@api private

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

@api private

    # File lib/puppet/pops/types/p_object_type.rb
558 def implementation_class=(cls)
559   raise ArgumentError, "attempt to redefine implementation class for #{label}" unless @implementation_class.nil?
560   @implementation_class = cls
561 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
571 def implementation_override=(block)
572   if !@implementation_class.nil? || instance_variable_defined?(:@implementation_override)
573     raise ArgumentError, "attempt to redefine implementation override for #{label}"
574   end
575   @implementation_override = block
576 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
833 def init_hash_type
834   @init_hash_type ||= create_init_hash_type
835 end
instance?(o, guard = nil) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
439 def instance?(o, guard = nil)
440   if o.is_a?(PuppetObject)
441     assignable?(o._pcore_type, guard)
442   else
443     name = o.class.name
444     return false if name.nil? # anonymous class that doesn't implement PuppetObject is not an instance
445     ir = Loaders.implementation_registry
446     type = ir.nil? ? nil : ir.type_for_module(name)
447     !type.nil? && assignable?(type, guard)
448   end
449 end
iterable?(guard = nil) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
916 def iterable?(guard = nil)
917   @parent.nil? ? false : @parent.iterable?(guard)
918 end
iterable_type(guard = nil) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
920 def iterable_type(guard = nil)
921   @parent.nil? ? false : @parent.iterable_type(guard)
922 end
kind_of_callable?(optional=true, guard = nil) click to toggle source
    # File lib/puppet/pops/types/p_object_type.rb
912 def kind_of_callable?(optional=true, guard = nil)
913   @parent.nil? ? false : @parent.kind_of_callable?(optional, guard)
914 end
label() click to toggle source

@api private

    # File lib/puppet/pops/types/p_object_type.rb
989 def label
990   @name || 'Object'
991 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
938 def members(include_parent = false)
939   get_members(include_parent, :both)
940 end
new_function() click to toggle source

@api private

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

@api private

     # File lib/puppet/pops/types/p_object_type.rb
 994 def resolved_parent
 995   parent = @parent
 996   while parent.is_a?(PTypeAliasType)
 997     parent = parent.resolved_type
 998   end
 999   parent
1000 end
simple_name() click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1002 def simple_name
1003   label.split(DOUBLE_COLON).last
1004 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
1012 def type_parameters(include_parent = false)
1013   all = {}
1014   collect_type_parameters(all, include_parent)
1015   all
1016 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
483 def write(value, serializer)
484   writer.write(self, value, serializer)
485 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
466 def writer=(writer)
467   @writer = writer
468 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
1022 def _assignable?(o, guard)
1023   if o.is_a?(PObjectType)
1024     if DEFAULT == self || self == o
1025       true
1026     else
1027       op = o.parent
1028       op.nil? ? false : assignable?(op, guard)
1029     end
1030   elsif o.is_a?(PObjectTypeExtension)
1031     assignable?(o.base_type, guard)
1032   else
1033     false
1034   end
1035 end
collect_equality_attributes(collector) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1053 def collect_equality_attributes(collector)
1054   parent = resolved_parent
1055   parent.collect_equality_attributes(collector) if parent.is_a?(PObjectType)
1056   if @equality.nil?
1057     # All attributes except constants participate
1058     collector.merge!(@attributes.reject { |_, attr| attr.kind == ATTRIBUTE_KIND_CONSTANT })
1059   else
1060     collector.merge!(Hash[@equality.map { |attr_name| [attr_name, @attributes[attr_name]] }])
1061   end
1062   nil
1063 end
collect_members(collector, include_parent, member_type) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1043 def collect_members(collector, include_parent, member_type)
1044   if include_parent
1045     parent = resolved_parent
1046     parent.collect_members(collector, include_parent, member_type) if parent.is_a?(PObjectType)
1047   end
1048   collector.merge!(@attributes) unless member_type == :functions
1049   collector.merge!(@functions) unless member_type == :attributes
1050   nil
1051 end
collect_type_parameters(collector, include_parent) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1065 def collect_type_parameters(collector, include_parent)
1066   if include_parent
1067     parent = resolved_parent
1068     parent.collect_type_parameters(collector, include_parent) if parent.is_a?(PObjectType)
1069   end
1070   collector.merge!(@type_parameters)
1071   nil
1072 end
get_members(include_parent, member_type) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1037 def get_members(include_parent, member_type)
1038   all = {}
1039   collect_members(all, include_parent, member_type)
1040   all
1041 end

Private Instance Methods

compressed_members_hash(features) click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1076 def compressed_members_hash(features)
1077   Hash[features.values.map do |feature|
1078     fh = feature._pcore_init_hash
1079     if fh.size == 1
1080       type = fh[KEY_TYPE]
1081       fh = type unless type.nil?
1082     end
1083     [feature.name, fh]
1084   end]
1085 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
1088 def find_equality_definer_of(attr)
1089   type = self
1090   while !type.nil? do
1091     p = type.resolved_parent
1092     return type unless p.is_a?(PObjectType)
1093     return type unless p.equality_attributes.include?(attr.name)
1094     type = p
1095   end
1096   nil
1097 end
guarded_recursion(guard, dflt) { |guard| ... } click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1099 def guarded_recursion(guard, dflt)
1100   if @self_recursion
1101     guard ||= RecursionGuard.new
1102     guard.with_this(self) { |state| (state & RecursionGuard::SELF_RECURSION_IN_THIS) == 0 ? yield(guard) : dflt }
1103   else
1104     yield(guard)
1105   end
1106 end
reader() click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1108 def reader
1109   @reader ||= Serialization::ObjectReader::INSTANCE
1110 end
writer() click to toggle source
     # File lib/puppet/pops/types/p_object_type.rb
1112 def writer
1113   @writer ||= Serialization::ObjectWriter::INSTANCE
1114 end