Class: Puppet::Pops::Model::CaseExpression

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, test, options = _pcore_type['options'].value) ⇒ CaseExpression

Returns a new instance of CaseExpression


1349
1350
1351
1352
1353
1354
# File 'lib/puppet/pops/model/ast.rb', line 1349

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

Instance Attribute Details

#optionsObject (readonly)


1347
1348
1349
# File 'lib/puppet/pops/model/ast.rb', line 1347

def options
  @options
end

#testObject (readonly)


1346
1347
1348
# File 'lib/puppet/pops/model/ast.rb', line 1346

def test
  @test
end

Class Method Details

._pcore_typeObject


1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
# File 'lib/puppet/pops/model/ast.rb', line 1309

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

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


1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
# File 'lib/puppet/pops/model/ast.rb', line 1335

def self.create(locator, offset, length, test, options = _pcore_type['options'].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::CaseExpression[test]', attrs['test'].type, test)
  ta.assert_instance_of('Puppet::AST::CaseExpression[options]', attrs['options'].type, options)
  new(locator, offset, length, test, options)
end

.from_asserted_hash(init_hash) ⇒ Object


1326
1327
1328
1329
1330
1331
1332
1333
# File 'lib/puppet/pops/model/ast.rb', line 1326

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

.from_hash(init_hash) ⇒ Object


1322
1323
1324
# File 'lib/puppet/pops/model/ast.rb', line 1322

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
# File 'lib/puppet/pops/model/ast.rb', line 1368

def _pcore_all_contents(path, &block)
  path << self
  unless @test.nil?
    block.call(@test, path)
    @test._pcore_all_contents(path, &block)
  end
  @options.each do |value|
    block.call(value, path)
    value._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:


1363
1364
1365
1366
# File 'lib/puppet/pops/model/ast.rb', line 1363

def _pcore_contents
  yield(@test) unless @test.nil?
  @options.each { |value| yield(value) }
end

#_pcore_init_hashObject


1356
1357
1358
1359
1360
1361
# File 'lib/puppet/pops/model/ast.rb', line 1356

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

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


1381
1382
1383
1384
1385
# File 'lib/puppet/pops/model/ast.rb', line 1381

def eql?(o)
  super &&
  @test.eql?(o.test) &&
  @options.eql?(o.options)
end