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.



1062
1063
1064
1065
1066
1067
# File 'lib/puppet/pops/model/ast.rb', line 1062

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)



1059
1060
1061
# File 'lib/puppet/pops/model/ast.rb', line 1059

def key
  @key
end

#valueObject (readonly)



1060
1061
1062
# File 'lib/puppet/pops/model/ast.rb', line 1060

def value
  @value
end

Class Method Details

._pcore_typeObject



1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
# File 'lib/puppet/pops/model/ast.rb', line 1023

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



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

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



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

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



1035
1036
1037
# File 'lib/puppet/pops/model/ast.rb', line 1035

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



1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
# File 'lib/puppet/pops/model/ast.rb', line 1081

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:



1076
1077
1078
1079
# File 'lib/puppet/pops/model/ast.rb', line 1076

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

#_pcore_init_hashObject



1069
1070
1071
1072
1073
1074
# File 'lib/puppet/pops/model/ast.rb', line 1069

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

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

Returns:

  • (Boolean)


1094
1095
1096
1097
1098
# File 'lib/puppet/pops/model/ast.rb', line 1094

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