Class: Puppet::Pops::Model::LiteralHash

Inherits:
Expression 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, entries = _pcore_type['entries'].value) ⇒ LiteralHash

Returns a new instance of LiteralHash.



1141
1142
1143
1144
1145
# File 'lib/puppet/pops/model/ast.rb', line 1141

def initialize(locator, offset, length, entries = _pcore_type['entries'].value)
  super(locator, offset, length)
  @hash = @hash ^ entries.hash
  @entries = entries
end

Instance Attribute Details

#entriesObject (readonly)



1139
1140
1141
# File 'lib/puppet/pops/model/ast.rb', line 1139

def entries
  @entries
end

Class Method Details

._pcore_typeObject



1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
# File 'lib/puppet/pops/model/ast.rb', line 1103

def self._pcore_type
  @_pcore_type ||=
    Types::PObjectType
      .new('Puppet::AST::LiteralHash', {
             'parent' => Expression._pcore_type,
             'attributes' => {
               'entries' => {
                 'type' => Types::PArrayType.new(KeyedEntry._pcore_type),
                 'value' => []
               }
             }
           })
end

.create(locator, offset, length, entries = _pcore_type['entries'].value) ⇒ Object



1129
1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/puppet/pops/model/ast.rb', line 1129

def self.create(locator, offset, length, entries = _pcore_type['entries'].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::LiteralHash[entries]', attrs['entries'].type, entries)
  new(locator, offset, length, entries)
end

.from_asserted_hash(init_hash) ⇒ Object



1121
1122
1123
1124
1125
1126
1127
# File 'lib/puppet/pops/model/ast.rb', line 1121

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash.fetch('entries') { _pcore_type['entries'].value })
end

.from_hash(init_hash) ⇒ Object



1117
1118
1119
# File 'lib/puppet/pops/model/ast.rb', line 1117

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



1157
1158
1159
1160
1161
1162
1163
1164
# File 'lib/puppet/pops/model/ast.rb', line 1157

def _pcore_all_contents(path, &block)
  path << self
  @entries.each do |value|
    block.call(value, path)
    value._pcore_all_contents(path, &block)
  end
  path.pop
end

#_pcore_contentsObject



1153
1154
1155
# File 'lib/puppet/pops/model/ast.rb', line 1153

def _pcore_contents
  @entries.each { |value| yield(value) }
end

#_pcore_init_hashObject



1147
1148
1149
1150
1151
# File 'lib/puppet/pops/model/ast.rb', line 1147

def _pcore_init_hash
  result = super
  result['entries'] = @entries unless _pcore_type['entries'].default_value?(@entries)
  result
end

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

Returns:

  • (Boolean)


1166
1167
1168
1169
# File 'lib/puppet/pops/model/ast.rb', line 1166

def eql?(o)
  super &&
  @entries.eql?(o.entries)
end