Class: Puppet::Pops::Types::PStructElement

Inherits:
TypedModelObject show all
Defined in:
lib/puppet/pops/types/types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TypedModelObject

_pcore_type, create_ptype, register_ptypes

Methods included from PuppetObject

#_pcore_all_contents, #_pcore_contents, #_pcore_init_hash, #_pcore_type

Constructor Details

#initialize(key_type, value_type) ⇒ PStructElement

Returns a new instance of PStructElement.



1854
1855
1856
1857
# File 'lib/puppet/pops/types/types.rb', line 1854

def initialize(key_type, value_type)
  @key_type = key_type
  @value_type = value_type
end

Instance Attribute Details

#key_typeObject



1837
1838
1839
# File 'lib/puppet/pops/types/types.rb', line 1837

def key_type
  @key_type
end

#value_typeObject



1837
1838
1839
# File 'lib/puppet/pops/types/types.rb', line 1837

def value_type
  @value_type
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1831
1832
1833
1834
1835
# File 'lib/puppet/pops/types/types.rb', line 1831

def self.register_ptype(loader, ir)
  @type = Pcore::create_object_type(loader, ir, self, 'Pcore::StructElement'.freeze, nil,
    'key_type' => PTypeType::DEFAULT,
    'value_type' => PTypeType::DEFAULT)
end

Instance Method Details

#<=>(o) ⇒ Object



1875
1876
1877
# File 'lib/puppet/pops/types/types.rb', line 1875

def <=>(o)
  self.name <=> o.name
end

#==(o) ⇒ Object



1883
1884
1885
# File 'lib/puppet/pops/types/types.rb', line 1883

def ==(o)
  self.class == o.class && value_type == o.value_type && key_type == o.key_type
end

#accept(visitor, guard) ⇒ Object



1839
1840
1841
1842
# File 'lib/puppet/pops/types/types.rb', line 1839

def accept(visitor, guard)
  @key_type.accept(visitor, guard)
  @value_type.accept(visitor, guard)
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


1879
1880
1881
# File 'lib/puppet/pops/types/types.rb', line 1879

def eql?(o)
  self == o
end

#generalizeObject



1859
1860
1861
1862
# File 'lib/puppet/pops/types/types.rb', line 1859

def generalize
  gv_type = @value_type.generalize
  @value_type.equal?(gv_type) ? self : PStructElement.new(@key_type, gv_type)
end

#hashObject



1844
1845
1846
# File 'lib/puppet/pops/types/types.rb', line 1844

def hash
  value_type.hash ^ key_type.hash
end

#nameObject



1848
1849
1850
1851
1852
# File 'lib/puppet/pops/types/types.rb', line 1848

def name
  k = key_type
  k = k.optional_type if k.is_a?(POptionalType)
  k.value
end

#normalize(guard = nil) ⇒ Object



1864
1865
1866
1867
# File 'lib/puppet/pops/types/types.rb', line 1864

def normalize(guard = nil)
  nv_type = @value_type.normalize(guard)
  @value_type.equal?(nv_type) ? self : PStructElement.new(@key_type, nv_type)
end

#replace_value_type(new_type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Special boostrap method to overcome the hen and egg problem with the Object initializer that contains types that are derived from Object (such as Annotation)



1891
1892
1893
# File 'lib/puppet/pops/types/types.rb', line 1891

def replace_value_type(new_type)
  @value_type = new_type
end

#resolve(loader) ⇒ Object



1869
1870
1871
1872
1873
# File 'lib/puppet/pops/types/types.rb', line 1869

def resolve(loader)
  rkey_type = @key_type.resolve(loader)
  rvalue_type = @value_type.resolve(loader)
  rkey_type.equal?(@key_type) && rvalue_type.equal?(@value_type) ? self : self.class.new(rkey_type, rvalue_type)
end