class Puppet::Pops::Types::PType
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 479 def self.new_function(type) 480 @new_function ||= Puppet::Functions.create_loaded_function(:new_type, type.loader) do 481 dispatch :from_string do 482 param 'String[1]', :type_string 483 end 484 485 def from_string(type_string) 486 TypeParser.singleton.parse(type_string, loader) 487 end 488 end 489 end
register_ptype(loader, ir)
click to toggle source
# File lib/puppet/pops/types/types.rb 468 def self.register_ptype(loader, ir) 469 create_ptype(loader, ir, 'AnyType', 470 'type' => { 471 KEY_TYPE => POptionalType.new(PTypeType::DEFAULT), 472 KEY_VALUE => nil 473 } 474 ) 475 end
Public Instance Methods
eql?(o)
click to toggle source
# File lib/puppet/pops/types/types.rb 528 def eql?(o) 529 self.class == o.class && @type == o.type 530 end
from_string(type_string)
click to toggle source
# File lib/puppet/pops/types/types.rb 485 def from_string(type_string) 486 TypeParser.singleton.parse(type_string, loader) 487 end
instance?(o, guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 491 def instance?(o, guard = nil) 492 if o.is_a?(PAnyType) 493 type.nil? || type.assignable?(o, guard) 494 elsif o.is_a?(Module) || o.is_a?(Puppet::Resource) || o.is_a?(Puppet::Parser::Resource) 495 @type.nil? ? true : assignable?(TypeCalculator.infer(o)) 496 else 497 false 498 end 499 end
iterable?(guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 501 def iterable?(guard = nil) 502 case @type 503 when PEnumType 504 true 505 when PIntegerType 506 @type.finite_range? 507 else 508 false 509 end 510 end
iterable_type(guard = nil)
click to toggle source
# File lib/puppet/pops/types/types.rb 512 def iterable_type(guard = nil) 513 # The types PIntegerType and PEnumType are Iterable 514 case @type 515 when PEnumType 516 # @type describes the element type perfectly since the iteration is made over the 517 # contained choices. 518 PIterableType.new(@type) 519 when PIntegerType 520 # @type describes the element type perfectly since the iteration is made over the 521 # specified range. 522 @type.finite_range? ? PIterableType.new(@type) : nil 523 else 524 nil 525 end 526 end
Protected Instance Methods
_assignable?(o, guard)
click to toggle source
@api private
# File lib/puppet/pops/types/types.rb 537 def _assignable?(o, guard) 538 return false unless o.is_a?(PTypeType) 539 return true if @type.nil? # wide enough to handle all types 540 return false if o.type.nil? # wider than t 541 @type.assignable?(o.type, guard) 542 end