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, #to_s

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


479
480
481
482
483
484
485
486
487
488
489
# File 'lib/puppet/pops/types/types.rb', line 479

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

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

.register_ptype(loader, ir) ⇒ Object


468
469
470
471
472
473
474
475
# File 'lib/puppet/pops/types/types.rb', line 468

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


528
529
530
# File 'lib/puppet/pops/types/types.rb', line 528

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

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


491
492
493
494
495
496
497
498
499
# File 'lib/puppet/pops/types/types.rb', line 491

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


501
502
503
504
505
506
507
508
509
510
# File 'lib/puppet/pops/types/types.rb', line 501

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

#iterable_type(guard = nil) ⇒ Object


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

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