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



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

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)


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

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

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

Returns:

  • (Boolean)


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

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

#iterable?(guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#iterable_type(guard = nil) ⇒ Object



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

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