Class: Puppet::Pops::Types::PStructType
- Inherits:
-
PAnyType
show all
- Includes:
- Enumerable
- Defined in:
- lib/puppet/pops/types/types.rb
Constant Summary
collapse
- DEFAULT =
PStructType.new(EMPTY_ARRAY)
Class Method Summary
collapse
Instance Method Summary
collapse
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.
1999
2000
2001
|
# File 'lib/puppet/pops/types/types.rb', line 1999
def initialize(elements)
@elements = elements.freeze
end
|
Class Method Details
.register_ptype(loader, ir) ⇒ Object
1995
1996
1997
|
# File 'lib/puppet/pops/types/types.rb', line 1995
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
2003
2004
2005
2006
|
# File 'lib/puppet/pops/types/types.rb', line 2003
def accept(visitor, guard)
super
@elements.each { |elem| elem.accept(visitor, guard) }
end
|
2008
2009
2010
2011
2012
2013
2014
|
# File 'lib/puppet/pops/types/types.rb', line 2008
def each
if block_given?
elements.each { |elem| yield elem }
else
elements.to_enum
end
end
|
2074
2075
2076
|
# File 'lib/puppet/pops/types/types.rb', line 2074
def elements
@elements
end
|
#eql?(o) ⇒ Boolean
2070
2071
2072
|
# File 'lib/puppet/pops/types/types.rb', line 2070
def eql?(o)
self.class == o.class && @elements == o.elements
end
|
#generalize ⇒ Object
2016
2017
2018
2019
2020
2021
2022
|
# File 'lib/puppet/pops/types/types.rb', line 2016
def generalize
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :generalize) { |altered| PStructType.new(altered) }
end
end
|
rubocop:enable Naming/MemoizedInstanceVariableName
2038
2039
2040
|
# File 'lib/puppet/pops/types/types.rb', line 2038
def hash
@elements.hash
end
|
#hashed_elements ⇒ Object
rubocop:disable Naming/MemoizedInstanceVariableName
2033
2034
2035
|
# File 'lib/puppet/pops/types/types.rb', line 2033
def hashed_elements
@hashed ||= @elements.each_with_object({}) { |e, memo| memo[e.name] = e; }
end
|
#instance?(o, guard = nil) ⇒ Boolean
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
|
# File 'lib/puppet/pops/types/types.rb', line 2078
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
2042
2043
2044
|
# File 'lib/puppet/pops/types/types.rb', line 2042
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
#new_function ⇒ Object
2096
2097
2098
2099
2100
|
# File 'lib/puppet/pops/types/types.rb', line 2096
def new_function
PHashType.new_function(self)
end
|
#normalize(guard = nil) ⇒ Object
2024
2025
2026
2027
2028
2029
2030
|
# File 'lib/puppet/pops/types/types.rb', line 2024
def normalize(guard = nil)
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :normalize, guard) { |altered| PStructType.new(altered) }
end
end
|
#resolve(loader) ⇒ Object
2060
2061
2062
2063
2064
2065
2066
2067
2068
|
# File 'lib/puppet/pops/types/types.rb', line 2060
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
|