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?, #check_self_recursion, #kind_of_callable?, #name, new_function, #really_instance?, #simple_name, simple_name, #to_alias_expanded_s, #to_s
_ptype, create_ptype, register_ptypes
#_ptype
Constructor Details
#initialize(elements) ⇒ PStructType
Returns a new instance of PStructType.
1719
1720
1721
|
# File 'lib/puppet/pops/types/types.rb', line 1719
def initialize(elements)
@elements = elements.freeze
end
|
Class Method Details
.register_ptype(loader, ir) ⇒ Object
1715
1716
1717
|
# File 'lib/puppet/pops/types/types.rb', line 1715
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
1723
1724
1725
1726
|
# File 'lib/puppet/pops/types/types.rb', line 1723
def accept(visitor, guard)
super
@elements.each { |elem| elem.accept(visitor, guard) }
end
|
1728
1729
1730
1731
1732
1733
1734
|
# File 'lib/puppet/pops/types/types.rb', line 1728
def each
if block_given?
elements.each { |elem| yield elem }
else
elements.to_enum
end
end
|
1791
1792
1793
|
# File 'lib/puppet/pops/types/types.rb', line 1791
def elements
@elements
end
|
#eql?(o) ⇒ Boolean
1787
1788
1789
|
# File 'lib/puppet/pops/types/types.rb', line 1787
def eql?(o)
self.class == o.class && @elements == o.elements
end
|
#generalize ⇒ Object
1736
1737
1738
1739
1740
1741
1742
|
# File 'lib/puppet/pops/types/types.rb', line 1736
def generalize
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :generalize) { |altered| PStructType.new(altered) }
end
end
|
1756
1757
1758
|
# File 'lib/puppet/pops/types/types.rb', line 1756
def hash
@elements.hash
end
|
#hashed_elements ⇒ Object
1752
1753
1754
|
# File 'lib/puppet/pops/types/types.rb', line 1752
def hashed_elements
@hashed ||= @elements.reduce({}) {|memo, e| memo[e.name] = e; memo }
end
|
#instance?(o, guard = nil) ⇒ Boolean
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
|
# File 'lib/puppet/pops/types/types.rb', line 1795
def instance?(o, guard = nil)
return false unless o.is_a?(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
1760
1761
1762
|
# File 'lib/puppet/pops/types/types.rb', line 1760
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
#new_function(loader) ⇒ Object
1811
1812
1813
1814
1815
|
# File 'lib/puppet/pops/types/types.rb', line 1811
def new_function(loader)
PHashType.new_function(self, loader)
end
|
#normalize(guard = nil) ⇒ Object
1744
1745
1746
1747
1748
1749
1750
|
# File 'lib/puppet/pops/types/types.rb', line 1744
def normalize(guard = nil)
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :normalize, guard) { |altered| PStructType.new(altered) }
end
end
|
#resolve(type_parser, loader) ⇒ Object
1777
1778
1779
1780
1781
1782
1783
1784
1785
|
# File 'lib/puppet/pops/types/types.rb', line 1777
def resolve(type_parser, loader)
changed = false
relements = @elements.map do |elem|
relem = elem.resolve(type_parser, loader)
changed ||= !relem.equal?(elem)
relem
end
changed ? self.class.new(relements) : self
end
|