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

Constructor Details

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

Returns a new instance of Program.



4684
4685
4686
4687
4688
4689
4690
# File 'lib/puppet/pops/model/ast.rb', line 4684

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)



4664
4665
4666
# File 'lib/puppet/pops/model/ast.rb', line 4664

def body
  @body
end

#definitionsObject (readonly)



4665
4666
4667
# File 'lib/puppet/pops/model/ast.rb', line 4665

def definitions
  @definitions
end

#locatorObject (readonly)



4666
4667
4668
# File 'lib/puppet/pops/model/ast.rb', line 4666

def locator
  @locator
end

Class Method Details

._pcore_typeObject



4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
# File 'lib/puppet/pops/model/ast.rb', line 4614

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



4655
4656
4657
4658
4659
4660
4661
4662
# File 'lib/puppet/pops/model/ast.rb', line 4655

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



4648
4649
4650
4651
4652
4653
# File 'lib/puppet/pops/model/ast.rb', line 4648

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



4644
4645
4646
# File 'lib/puppet/pops/model/ast.rb', line 4644

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



4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
# File 'lib/puppet/pops/model/ast.rb', line 4705

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:



4700
4701
4702
4703
# File 'lib/puppet/pops/model/ast.rb', line 4700

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

#_pcore_init_hashObject



4692
4693
4694
4695
4696
4697
4698
# File 'lib/puppet/pops/model/ast.rb', line 4692

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



4668
4669
4670
# File 'lib/puppet/pops/model/ast.rb', line 4668

def current
  self
end

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

Returns:

  • (Boolean)


4718
4719
4720
4721
4722
4723
# File 'lib/puppet/pops/model/ast.rb', line 4718

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

#line_offsetsObject



4680
4681
4682
# File 'lib/puppet/pops/model/ast.rb', line 4680

def line_offsets
  @locator.line_index
end

#source_refObject



4676
4677
4678
# File 'lib/puppet/pops/model/ast.rb', line 4676

def source_ref
  @locator.file
end

#source_textObject



4672
4673
4674
# File 'lib/puppet/pops/model/ast.rb', line 4672

def source_text
  @locator.string
end