Class: Puppet::Pops::Model::Program

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

Instance Attribute Summary collapse

Attributes inherited from PopsObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PopsObject

#to_s

Methods included from Types::PuppetObject

#_pcore_type, #to_s

Constructor Details

#initialize(locator, body = nil, definitions = _pcore_type['definitions'].value) ⇒ Program

Returns a new instance of Program.


4521
4522
4523
4524
4525
4526
4527
# File 'lib/puppet/pops/model/ast.rb', line 4521

def initialize(locator, body = nil, definitions = _pcore_type['definitions'].value)
  super()
  @hash = @hash ^ body.hash ^ definitions.hash ^ locator.hash
  @body = body
  @definitions = definitions
  @locator = locator
end

Instance Attribute Details

#bodyObject (readonly)


4501
4502
4503
# File 'lib/puppet/pops/model/ast.rb', line 4501

def body
  @body
end

#definitionsObject (readonly)


4502
4503
4504
# File 'lib/puppet/pops/model/ast.rb', line 4502

def definitions
  @definitions
end

#locatorObject (readonly)


4503
4504
4505
# File 'lib/puppet/pops/model/ast.rb', line 4503

def locator
  @locator
end

Class Method Details

._pcore_typeObject


4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
# File 'lib/puppet/pops/model/ast.rb', line 4451

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::Program', {
    'parent' => PopsObject._pcore_type,
    'attributes' => {
      'body' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      },
      'definitions' => {
        'type' => Types::PArrayType.new(Definition._pcore_type),
        'kind' => 'reference',
        'value' => []
      },
      'source_text' => {
        'type' => Types::PStringType::DEFAULT,
        'kind' => 'derived'
      },
      'source_ref' => {
        'type' => Types::PStringType::DEFAULT,
        'kind' => 'derived'
      },
      'line_offsets' => {
        'type' => Types::PArrayType.new(Types::PIntegerType::DEFAULT),
        'kind' => 'derived'
      },
      'locator' => Parser::Locator::Locator19._pcore_type
    }
  })
end

.create(locator, body = nil, definitions = _pcore_type['definitions'].value) ⇒ Object


4492
4493
4494
4495
4496
4497
4498
4499
# File 'lib/puppet/pops/model/ast.rb', line 4492

def self.create(locator, body = nil, definitions = _pcore_type['definitions'].value)
  ta = Types::TypeAsserter
  attrs = _pcore_type.attributes(true)
  ta.assert_instance_of('Puppet::AST::Program[body]', attrs['body'].type, body)
  ta.assert_instance_of('Puppet::AST::Program[definitions]', attrs['definitions'].type, definitions)
  ta.assert_instance_of('Puppet::AST::Program[locator]', attrs['locator'].type, locator)
  new(locator, body, definitions)
end

.from_asserted_hash(init_hash) ⇒ Object


4485
4486
4487
4488
4489
4490
# File 'lib/puppet/pops/model/ast.rb', line 4485

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['body'],
    init_hash.fetch('definitions') { _pcore_type['definitions'].value })
end

.from_hash(init_hash) ⇒ Object


4481
4482
4483
# File 'lib/puppet/pops/model/ast.rb', line 4481

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
# File 'lib/puppet/pops/model/ast.rb', line 4542

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

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

Yields:


4537
4538
4539
4540
# File 'lib/puppet/pops/model/ast.rb', line 4537

def _pcore_contents
  yield(@body) unless @body.nil?
  yield(@locator) unless @locator.nil?
end

#_pcore_init_hashObject


4529
4530
4531
4532
4533
4534
4535
# File 'lib/puppet/pops/model/ast.rb', line 4529

def _pcore_init_hash
  result = super
  result['body'] = @body unless @body == nil
  result['definitions'] = @definitions unless _pcore_type['definitions'].default_value?(@definitions)
  result['locator'] = @locator
  result
end

#currentObject


4505
4506
4507
# File 'lib/puppet/pops/model/ast.rb', line 4505

def current
  self
end

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

Returns:

  • (Boolean)

4555
4556
4557
4558
4559
4560
# File 'lib/puppet/pops/model/ast.rb', line 4555

def eql?(o)
  super &&
  @body.eql?(o.body) &&
  @definitions.eql?(o.definitions) &&
  @locator.eql?(o.locator)
end

#line_offsetsObject


4517
4518
4519
# File 'lib/puppet/pops/model/ast.rb', line 4517

def line_offsets
  @locator.line_index
end

#source_refObject


4513
4514
4515
# File 'lib/puppet/pops/model/ast.rb', line 4513

def source_ref
  @locator.file
end

#source_textObject


4509
4510
4511
# File 'lib/puppet/pops/model/ast.rb', line 4509

def source_text
  @locator.string
end