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, #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.
1792
1793
1794
|
# File 'lib/puppet/pops/types/types.rb', line 1792
def initialize(elements)
@elements = elements.freeze
end
|
Class Method Details
.register_ptype(loader, ir) ⇒ Object
1788
1789
1790
|
# File 'lib/puppet/pops/types/types.rb', line 1788
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
1796
1797
1798
1799
|
# File 'lib/puppet/pops/types/types.rb', line 1796
def accept(visitor, guard)
super
@elements.each { |elem| elem.accept(visitor, guard) }
end
|
1801
1802
1803
1804
1805
1806
1807
|
# File 'lib/puppet/pops/types/types.rb', line 1801
def each
if block_given?
elements.each { |elem| yield elem }
else
elements.to_enum
end
end
|
1864
1865
1866
|
# File 'lib/puppet/pops/types/types.rb', line 1864
def elements
@elements
end
|
#eql?(o) ⇒ Boolean
1860
1861
1862
|
# File 'lib/puppet/pops/types/types.rb', line 1860
def eql?(o)
self.class == o.class && @elements == o.elements
end
|
#generalize ⇒ Object
1809
1810
1811
1812
1813
1814
1815
|
# File 'lib/puppet/pops/types/types.rb', line 1809
def generalize
if @elements.empty?
DEFAULT
else
alter_type_array(@elements, :generalize) { |altered| PStructType.new(altered) }
end
end
|
1829
1830
1831
|
# File 'lib/puppet/pops/types/types.rb', line 1829
def hash
@elements.hash
end
|
#hashed_elements ⇒ Object
1825
1826
1827
|
# File 'lib/puppet/pops/types/types.rb', line 1825
def hashed_elements
@hashed ||= @elements.reduce({}) {|memo, e| memo[e.name] = e; memo }
end
|
#instance?(o, guard = nil) ⇒ Boolean
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
|
# File 'lib/puppet/pops/types/types.rb', line 1868
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
1833
1834
1835
|
# File 'lib/puppet/pops/types/types.rb', line 1833
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
#new_function(loader) ⇒ Object
1884
1885
1886
1887
1888
|
# File 'lib/puppet/pops/types/types.rb', line 1884
def new_function(loader)
PHashType.new_function(self, loader)
end
|
#normalize(guard = nil) ⇒ Object
1817
1818
1819
1820
1821
1822
1823
|
# File 'lib/puppet/pops/types/types.rb', line 1817
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
1850
1851
1852
1853
1854
1855
1856
1857
1858
|
# File 'lib/puppet/pops/types/types.rb', line 1850
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
|