class Puppet::Pops::Types::PTypeType

The type of types. @api public

Constants

DEFAULT

Public Class Methods

new_function(type) click to toggle source

Returns a new function that produces a Type instance

    # File lib/puppet/pops/types/types.rb
478 def self.new_function(type)
479   @new_function ||= Puppet::Functions.create_loaded_function(:new_type, type.loader) do
480     dispatch :from_string do
481       param 'String[1]', :type_string
482     end
483 
484     def from_string(type_string)
485       TypeParser.singleton.parse(type_string, loader)
486     end
487   end
488 end
register_ptype(loader, ir) click to toggle source
    # File lib/puppet/pops/types/types.rb
467 def self.register_ptype(loader, ir)
468   create_ptype(loader, ir, 'AnyType',
469      'type' => {
470        KEY_TYPE => POptionalType.new(PTypeType::DEFAULT),
471        KEY_VALUE => nil
472      }
473   )
474 end

Public Instance Methods

eql?(o) click to toggle source
    # File lib/puppet/pops/types/types.rb
527 def eql?(o)
528   self.class == o.class && @type == o.type
529 end
from_string(type_string) click to toggle source
    # File lib/puppet/pops/types/types.rb
484 def from_string(type_string)
485   TypeParser.singleton.parse(type_string, loader)
486 end
instance?(o, guard = nil) click to toggle source
    # File lib/puppet/pops/types/types.rb
490 def instance?(o, guard = nil)
491   if o.is_a?(PAnyType)
492     type.nil? || type.assignable?(o, guard)
493   elsif o.is_a?(Module) || o.is_a?(Puppet::Resource) || o.is_a?(Puppet::Parser::Resource)
494     @type.nil? ? true : assignable?(TypeCalculator.infer(o))
495   else
496     false
497   end
498 end
iterable?(guard = nil) click to toggle source
    # File lib/puppet/pops/types/types.rb
500 def iterable?(guard = nil)
501   case @type
502   when PEnumType
503     true
504   when PIntegerType
505     @type.finite_range?
506   else
507     false
508   end
509 end
iterable_type(guard = nil) click to toggle source
    # File lib/puppet/pops/types/types.rb
511 def iterable_type(guard = nil)
512   # The types PIntegerType and PEnumType are Iterable
513   case @type
514   when PEnumType
515     # @type describes the element type perfectly since the iteration is made over the
516     # contained choices.
517     PIterableType.new(@type)
518   when PIntegerType
519     # @type describes the element type perfectly since the iteration is made over the
520     # specified range.
521     @type.finite_range? ? PIterableType.new(@type) : nil
522   else
523     nil
524   end
525 end

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

    # File lib/puppet/pops/types/types.rb
536 def _assignable?(o, guard)
537   return false unless o.is_a?(PTypeType)
538   return true if @type.nil? # wide enough to handle all types
539   return false if o.type.nil? # wider than t
540   @type.assignable?(o.type, guard)
541 end