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

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

Overview

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.

API:

  • private

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.

API:

  • private

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?, #check_self_recursion, #create, #eql?, #generalize, #hash, #iterable?, #iterable_type, #kind_of_callable?, #name, new_function, #really_instance?, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s

Methods inherited from TypedModelObject

_ptype, create_ptype, register_ptypes

Methods included from Visitable

#accept

Methods included from PuppetObject

#_ptype

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.

API:

  • private



505
506
507
# File 'lib/puppet/pops/types/types.rb', line 505

def initialize(type = nil)
  super(type.class == 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.

API:

  • private



496
497
498
499
500
501
502
503
# File 'lib/puppet/pops/types/types.rb', line 496

def self.register_ptype(loader, ir)
  create_ptype(loader, ir, 'AnyType',
     'type' => {
       KEY_TYPE => POptionalType.new(PType::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:

API:

  • private



509
510
511
# File 'lib/puppet/pops/types/types.rb', line 509

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

#new_function(loader) ⇒ 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.

API:

  • private



530
531
532
533
534
535
536
537
# File 'lib/puppet/pops/types/types.rb', line 530

def new_function(loader)
  # If only NotUndef, then use Unit's null converter
  if type.nil?
    PUnitType.new_function(self.class, loader)
  else
    type.new_function(loader)
  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.

API:

  • private



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

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