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, #to_s

Constructor Details

#initialize(key_type, value_type) ⇒ PStructElement

Returns a new instance of PStructElement.


1944
1945
1946
1947
# File 'lib/puppet/pops/types/types.rb', line 1944

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

Instance Attribute Details

#key_typeObject


1927
1928
1929
# File 'lib/puppet/pops/types/types.rb', line 1927

def key_type
  @key_type
end

#value_typeObject


1927
1928
1929
# File 'lib/puppet/pops/types/types.rb', line 1927

def value_type
  @value_type
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object


1921
1922
1923
1924
1925
# File 'lib/puppet/pops/types/types.rb', line 1921

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


1965
1966
1967
# File 'lib/puppet/pops/types/types.rb', line 1965

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

#==(o) ⇒ Object


1973
1974
1975
# File 'lib/puppet/pops/types/types.rb', line 1973

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

#accept(visitor, guard) ⇒ Object


1929
1930
1931
1932
# File 'lib/puppet/pops/types/types.rb', line 1929

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

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

1969
1970
1971
# File 'lib/puppet/pops/types/types.rb', line 1969

def eql?(o)
  self == o
end

#generalizeObject


1949
1950
1951
1952
# File 'lib/puppet/pops/types/types.rb', line 1949

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

#hashObject


1934
1935
1936
# File 'lib/puppet/pops/types/types.rb', line 1934

def hash
  value_type.hash ^ key_type.hash
end

#nameObject


1938
1939
1940
1941
1942
# File 'lib/puppet/pops/types/types.rb', line 1938

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

#normalize(guard = nil) ⇒ Object


1954
1955
1956
1957
# File 'lib/puppet/pops/types/types.rb', line 1954

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)


1981
1982
1983
# File 'lib/puppet/pops/types/types.rb', line 1981

def replace_value_type(new_type)
  @value_type = new_type
end

#resolve(loader) ⇒ Object


1959
1960
1961
1962
1963
# File 'lib/puppet/pops/types/types.rb', line 1959

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