Class: Puppet::Pops::Types::PStructType
Constant Summary
collapse
- DEFAULT =
PStructType.new(EMPTY_ARRAY)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Enumerable
#uniq
Methods inherited from PAnyType
#==, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, create, #create, #kind_of_callable?, #loader, #name, new_function, #really_instance?, #roundtrip_with_string?, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_pcore_type, create_ptype, register_ptypes
#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type, #to_s
Constructor Details
#initialize(elements) ⇒ PStructType
Returns a new instance of PStructType.
1993
1994
1995
|
# File 'lib/puppet/pops/types/types.rb', line 1993
def initialize(elements)
@elements = elements.freeze
end
|
Class Method Details
.register_ptype(loader, ir) ⇒ Object
1989
1990
1991
|
# File 'lib/puppet/pops/types/types.rb', line 1989
def self.register_ptype(loader, ir)
create_ptype(loader, ir, 'AnyType', 'elements' => PArrayType.new(PTypeReferenceType.new('Pcore::StructElement')))
end
|
Instance Method Details
#accept(visitor, guard) ⇒ Object
1997
1998
1999
2000
|
# File 'lib/puppet/pops/types/types.rb', line 1997
def accept(visitor, guard)
super
@elements.each { |elem| elem.accept(visitor, guard) }
end
|
2002
2003
2004
2005
2006
2007
2008
|
# File 'lib/puppet/pops/types/types.rb', line 2002
def each
if block_given?
elements.each { |elem| yield elem }
else
elements.to_enum
end
end
|
2064
2065
2066
|
# File 'lib/puppet/pops/types/types.rb', line 2064
def elements
@elements
end
|
#eql?(o) ⇒ Boolean
2060
2061
2062
|
# File 'lib/puppet/pops/types/types.rb', line 2060
def eql?(o)
self.class == o.class && @elements == o.elements
end
|
#generalize ⇒ Object
2010
2011
2012
2013
2014
2015
2016
|
# File 'lib/puppet/pops/types/types.rb', line 2010
def generalize
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :generalize) { |altered| PStructType.new(altered) }
end
end
|
2030
2031
2032
|
# File 'lib/puppet/pops/types/types.rb', line 2030
def hash
@elements.hash
end
|
#hashed_elements ⇒ Object
2026
2027
2028
|
# File 'lib/puppet/pops/types/types.rb', line 2026
def hashed_elements
@hashed ||= @elements.reduce({}) {|memo, e| memo[e.name] = e; memo }
end
|
#instance?(o, guard = nil) ⇒ Boolean
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
|
# File 'lib/puppet/pops/types/types.rb', line 2068
def instance?(o, guard = nil)
return false unless o.instance_of?(Hash)
matched = 0
@elements.all? do |e|
key = e.name
v = o[key]
if v.nil? && !o.include?(key)
e.key_type.assignable?(PUndefType::DEFAULT, guard)
else
matched += 1
e.value_type.instance?(v, guard)
end
end && matched == o.size
end
|
#iterable?(guard = nil) ⇒ Boolean
2034
2035
2036
|
# File 'lib/puppet/pops/types/types.rb', line 2034
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
#new_function ⇒ Object
2085
2086
2087
2088
2089
|
# File 'lib/puppet/pops/types/types.rb', line 2085
def new_function
PHashType.new_function(self)
end
|
#normalize(guard = nil) ⇒ Object
2018
2019
2020
2021
2022
2023
2024
|
# File 'lib/puppet/pops/types/types.rb', line 2018
def normalize(guard = nil)
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :normalize, guard) { |altered| PStructType.new(altered) }
end
end
|
#resolve(loader) ⇒ Object
2050
2051
2052
2053
2054
2055
2056
2057
2058
|
# File 'lib/puppet/pops/types/types.rb', line 2050
def resolve(loader)
changed = false
relements = @elements.map do |elem|
relem = elem.resolve(loader)
changed ||= !relem.equal?(elem)
relem
end
changed ? self.class.new(relements) : self
end
|