Class: Puppet::Pops::Model::KeyedEntry

Inherits:
Positioned show all
Defined in:
lib/puppet/pops/model/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Positioned

#length, #locator, #offset

Attributes inherited from PopsObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Positioned

#file, #line, #pos

Methods inherited from PopsObject

#to_s

Methods included from Types::PuppetObject

#_pcore_type, #to_s

Constructor Details

#initialize(locator, offset, length, key, value) ⇒ KeyedEntry

Returns a new instance of KeyedEntry


1041
1042
1043
1044
1045
1046
# File 'lib/puppet/pops/model/ast.rb', line 1041

def initialize(locator, offset, length, key, value)
  super(locator, offset, length)
  @hash = @hash ^ key.hash ^ value.hash
  @key = key
  @value = value
end

Instance Attribute Details

#keyObject (readonly)


1038
1039
1040
# File 'lib/puppet/pops/model/ast.rb', line 1038

def key
  @key
end

#valueObject (readonly)


1039
1040
1041
# File 'lib/puppet/pops/model/ast.rb', line 1039

def value
  @value
end

Class Method Details

._pcore_typeObject


1004
1005
1006
1007
1008
1009
1010
1011
1012
# File 'lib/puppet/pops/model/ast.rb', line 1004

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::KeyedEntry', {
    'parent' => Positioned._pcore_type,
    'attributes' => {
      'key' => Expression._pcore_type,
      'value' => Expression._pcore_type
    }
  })
end

.create(locator, offset, length, key, value) ⇒ Object


1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
# File 'lib/puppet/pops/model/ast.rb', line 1027

def self.create(locator, offset, length, key, value)
  ta = Types::TypeAsserter
  attrs = _pcore_type.attributes(true)
  ta.assert_instance_of('Puppet::AST::Positioned[locator]', attrs['locator'].type, locator)
  ta.assert_instance_of('Puppet::AST::Positioned[offset]', attrs['offset'].type, offset)
  ta.assert_instance_of('Puppet::AST::Positioned[length]', attrs['length'].type, length)
  ta.assert_instance_of('Puppet::AST::KeyedEntry[key]', attrs['key'].type, key)
  ta.assert_instance_of('Puppet::AST::KeyedEntry[value]', attrs['value'].type, value)
  new(locator, offset, length, key, value)
end

.from_asserted_hash(init_hash) ⇒ Object


1018
1019
1020
1021
1022
1023
1024
1025
# File 'lib/puppet/pops/model/ast.rb', line 1018

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['key'],
    init_hash['value'])
end

.from_hash(init_hash) ⇒ Object


1014
1015
1016
# File 'lib/puppet/pops/model/ast.rb', line 1014

def self.from_hash(init_hash)
  from_asserted_hash(Types::TypeAsserter.assert_instance_of('Puppet::AST::KeyedEntry initializer', _pcore_type.init_hash_type, init_hash))
end

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
# File 'lib/puppet/pops/model/ast.rb', line 1060

def _pcore_all_contents(path, &block)
  path << self
  unless @key.nil?
    block.call(@key, path)
    @key._pcore_all_contents(path, &block)
  end
  unless @value.nil?
    block.call(@value, path)
    @value._pcore_all_contents(path, &block)
  end
  path.pop
end

#_pcore_contents {|@key| ... } ⇒ Object

Yields:


1055
1056
1057
1058
# File 'lib/puppet/pops/model/ast.rb', line 1055

def _pcore_contents
  yield(@key) unless @key.nil?
  yield(@value) unless @value.nil?
end

#_pcore_init_hashObject


1048
1049
1050
1051
1052
1053
# File 'lib/puppet/pops/model/ast.rb', line 1048

def _pcore_init_hash
  result = super
  result['key'] = @key
  result['value'] = @value
  result
end

#eql?(o) ⇒ Boolean Also known as: ==


1073
1074
1075
1076
1077
# File 'lib/puppet/pops/model/ast.rb', line 1073

def eql?(o)
  super &&
  @key.eql?(o.key) &&
  @value.eql?(o.value)
end