Class: Puppet::Pops::Types::POptionalType
Overview
Represents a type that accept PUndefType instead of the type parameter required_type - is a short hand for Variant[T, Undef]
Constant Summary
collapse
- DEFAULT =
POptionalType.new(nil)
Instance Attribute Summary
#type
Class Method Summary
collapse
Instance Method Summary
collapse
#accept, #eql?, #generalize, #hash, #initialize, #resolve
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #check_self_recursion, #eql?, #generalize, #hash, #iterable?, #iterable_type, #name, new_function, #really_instance?, #resolve, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_ptype, create_ptype, register_ptypes
Methods included from Visitable
#accept
#_ptype
Class Method Details
.register_ptype(loader, ir) ⇒ Object
2885
2886
2887
2888
2889
2890
2891
2892
|
# File 'lib/puppet/pops/types/types.rb', line 2885
def self.register_ptype(loader, ir)
create_ptype(loader, ir, 'CatalogEntryType',
'type' => {
KEY_TYPE => POptionalType.new(PType::DEFAULT),
KEY_VALUE => nil
}
)
end
|
Instance Method Details
#instance?(o, guard = nil) ⇒ Boolean
2902
2903
2904
|
# File 'lib/puppet/pops/types/types.rb', line 2902
def instance?(o, guard = nil)
PUndefType::DEFAULT.instance?(o, guard) || (!@type.nil? && @type.instance?(o, guard))
end
|
#kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
2898
2899
2900
|
# File 'lib/puppet/pops/types/types.rb', line 2898
def kind_of_callable?(optional=true, guard = nil)
optional && !@type.nil? && @type.kind_of_callable?(optional, guard)
end
|
#new_function(loader) ⇒ Object
2923
2924
2925
|
# File 'lib/puppet/pops/types/types.rb', line 2923
def new_function(loader)
optional_type.new_function(loader)
end
|
#normalize(guard = nil) ⇒ Object
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
|
# File 'lib/puppet/pops/types/types.rb', line 2906
def normalize(guard = nil)
n = super
if n.type.nil?
n
else
if n.type.is_a?(PNotUndefType)
POptionalType.new(n.type.type).normalize
elsif n.type.assignable?(PUndefType::DEFAULT)
n.type
else
n
end
end
end
|
#optional_type ⇒ Object
2894
2895
2896
|
# File 'lib/puppet/pops/types/types.rb', line 2894
def optional_type
@type
end
|