Class: Puppet::Pops::Types::PTypeType

Inherits:
PTypeWithContainedType show all
Defined in:
lib/puppet/pops/types/types.rb

Overview

The type of types.

Constant Summary collapse

DEFAULT =
PTypeType.new(nil)

Instance Attribute Summary

Attributes inherited from PTypeWithContainedType

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PTypeWithContainedType

#accept, #generalize, #hash, #initialize, #normalize, #resolve

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, create, #create, #generalize, #hash, #kind_of_callable?, #loader, #name, #new_function, #normalize, #really_instance?, #resolve, #roundtrip_with_string?, simple_name, #simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_pcore_type, create_ptype, register_ptypes

Methods included from Visitable

#accept

Methods included from PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type

Constructor Details

This class inherits a constructor from Puppet::Pops::Types::PTypeWithContainedType

Class Method Details

.new_function(type) ⇒ Object

Returns a new function that produces a Type instance



476
477
478
479
480
481
482
483
484
485
486
# File 'lib/puppet/pops/types/types.rb', line 476

def self.new_function(type)
  @new_function ||= Puppet::Functions.create_loaded_function(:new_type, type.loader) do
    dispatch :from_string do
      param 'String', :type_string
    end

    def from_string(type_string)
      TypeParser.singleton.parse(type_string, loader)
    end
  end
end

.register_ptype(loader, ir) ⇒ Object



465
466
467
468
469
470
471
472
# File 'lib/puppet/pops/types/types.rb', line 465

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'AnyType',
     'type' => {
       KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
       KEY_VALUE => nil
     }
  )
end

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


525
526
527
# File 'lib/puppet/pops/types/types.rb', line 525

def eql?(o)
  self.class == o.class && @type == o.type
end

#instance?(o, guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


488
489
490
491
492
493
494
495
496
# File 'lib/puppet/pops/types/types.rb', line 488

def instance?(o, guard = nil)
  if o.is_a?(PAnyType)
    type.nil? || type.assignable?(o, guard)
  elsif o.is_a?(Module) || o.is_a?(Puppet::Resource) || o.is_a?(Puppet::Parser::Resource)
    @type.nil? ? true : assignable?(TypeCalculator.infer(o))
  else
    false
  end
end

#iterable?(guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


498
499
500
501
502
503
504
505
506
507
# File 'lib/puppet/pops/types/types.rb', line 498

def iterable?(guard = nil)
  case @type
  when PEnumType
    true
  when PIntegerType
    @type.finite_range?
  else
    false
  end
end

#iterable_type(guard = nil) ⇒ Object



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/puppet/pops/types/types.rb', line 509

def iterable_type(guard = nil)
  # The types PIntegerType and PEnumType are Iterable
  case @type
  when PEnumType
    # @type describes the element type perfectly since the iteration is made over the
    # contained choices.
    PIterableType.new(@type)
  when PIntegerType
    # @type describes the element type perfectly since the iteration is made over the
    # specified range.
    @type.finite_range? ? PIterableType.new(@type) : nil
  else
    nil
  end
end