Class: Puppet::Pops::Types::PNotUndefType Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

DEFAULT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

PNotUndefType.new

Instance Attribute Summary

Attributes inherited from PTypeWithContainedType

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PTypeWithContainedType

#accept, #eql?, #generalize, #hash, #resolve

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, #create, create, #eql?, #generalize, #hash, #iterable?, #iterable_type, #kind_of_callable?, #loader, #name, new_function, #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

#initialize(type = nil) ⇒ PNotUndefType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PNotUndefType.



559
560
561
# File 'lib/puppet/pops/types/types.rb', line 559

def initialize(type = nil)
  super(type.instance_of?(PAnyType) ? nil : type)
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



551
552
553
554
555
556
557
# File 'lib/puppet/pops/types/types.rb', line 551

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

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


563
564
565
# File 'lib/puppet/pops/types/types.rb', line 563

def instance?(o, guard = nil)
  !(o.nil? || o == :undef) && (@type.nil? || @type.instance?(o, guard))
end

#new_functionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



582
583
584
585
586
587
588
589
# File 'lib/puppet/pops/types/types.rb', line 582

def new_function
  # If only NotUndef, then use Unit's null converter
  if type.nil?
    PUnitType.new_function(self)
  else
    type.new_function
  end
end

#normalize(guard = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/puppet/pops/types/types.rb', line 567

def normalize(guard = nil)
  n = super
  if n.type.nil?
    n
  elsif n.type.is_a?(POptionalType)
    PNotUndefType.new(n.type.type).normalize
  # No point in having an optional in a NotUndef
  elsif !n.type.assignable?(PUndefType::DEFAULT)
    # THe type is NotUndef anyway, so it can be stripped of
    n.type
  else
    n
  end
end