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.



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

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

Instance Attribute Details

#key_typeObject



1730
1731
1732
# File 'lib/puppet/pops/types/types.rb', line 1730

def key_type
  @key_type
end

#value_typeObject



1730
1731
1732
# File 'lib/puppet/pops/types/types.rb', line 1730

def value_type
  @value_type
end

Class Method Details

.register_ptype(loader, ir) ⇒ Object



1724
1725
1726
1727
1728
# File 'lib/puppet/pops/types/types.rb', line 1724

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



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

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

#==(o) ⇒ Object



1778
1779
1780
# File 'lib/puppet/pops/types/types.rb', line 1778

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

#accept(visitor, guard) ⇒ Object



1732
1733
1734
1735
# File 'lib/puppet/pops/types/types.rb', line 1732

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

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(o)
  self == o
end

#generalizeObject



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

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

#hashObject



1737
1738
1739
# File 'lib/puppet/pops/types/types.rb', line 1737

def hash
  value_type.hash ^ key_type.hash
end

#nameObject



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

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

#normalize(guard = nil) ⇒ Object



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

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



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

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