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

_ptype, create_ptype, register_ptypes

Methods included from PuppetObject

#_ptype

Constructor Details

#initialize(key_type, value_type) ⇒ PStructElement

Returns a new instance of PStructElement.



1763
1764
1765
1766
# File 'lib/puppet/pops/types/types.rb', line 1763

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

Instance Attribute Details

#key_typeObject



1746
1747
1748
# File 'lib/puppet/pops/types/types.rb', line 1746

def key_type
  @key_type
end

#value_typeObject



1746
1747
1748
# File 'lib/puppet/pops/types/types.rb', line 1746

def value_type
  @value_type
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1740
1741
1742
1743
1744
# File 'lib/puppet/pops/types/types.rb', line 1740

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

Instance Method Details

#<=>(o) ⇒ Object



1786
1787
1788
# File 'lib/puppet/pops/types/types.rb', line 1786

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

#==(o) ⇒ Object



1794
1795
1796
# File 'lib/puppet/pops/types/types.rb', line 1794

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

#accept(visitor, guard) ⇒ Object



1748
1749
1750
1751
# File 'lib/puppet/pops/types/types.rb', line 1748

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

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


1790
1791
1792
# File 'lib/puppet/pops/types/types.rb', line 1790

def eql?(o)
  self == o
end

#generalizeObject



1768
1769
1770
1771
# File 'lib/puppet/pops/types/types.rb', line 1768

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

#hashObject



1753
1754
1755
# File 'lib/puppet/pops/types/types.rb', line 1753

def hash
  value_type.hash ^ key_type.hash
end

#nameObject



1757
1758
1759
1760
1761
# File 'lib/puppet/pops/types/types.rb', line 1757

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

#normalize(guard = nil) ⇒ Object



1773
1774
1775
1776
# File 'lib/puppet/pops/types/types.rb', line 1773

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

#resolve(type_parser, loader) ⇒ Object



1778
1779
1780
1781
1782
1783
1784
# File 'lib/puppet/pops/types/types.rb', line 1778

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