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


4807
4808
4809
4810
4811
4812
4813
# File 'lib/puppet/pops/model/ast.rb', line 4807

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)


4787
4788
4789
# File 'lib/puppet/pops/model/ast.rb', line 4787

def body
  @body
end

#definitionsObject (readonly)


4788
4789
4790
# File 'lib/puppet/pops/model/ast.rb', line 4788

def definitions
  @definitions
end

#locatorObject (readonly)


4789
4790
4791
# File 'lib/puppet/pops/model/ast.rb', line 4789

def locator
  @locator
end

Class Method Details

._pcore_typeObject


4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
# File 'lib/puppet/pops/model/ast.rb', line 4737

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


4778
4779
4780
4781
4782
4783
4784
4785
# File 'lib/puppet/pops/model/ast.rb', line 4778

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


4771
4772
4773
4774
4775
4776
# File 'lib/puppet/pops/model/ast.rb', line 4771

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


4767
4768
4769
# File 'lib/puppet/pops/model/ast.rb', line 4767

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


4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
# File 'lib/puppet/pops/model/ast.rb', line 4828

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:


4823
4824
4825
4826
# File 'lib/puppet/pops/model/ast.rb', line 4823

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

#_pcore_init_hashObject


4815
4816
4817
4818
4819
4820
4821
# File 'lib/puppet/pops/model/ast.rb', line 4815

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


4791
4792
4793
# File 'lib/puppet/pops/model/ast.rb', line 4791

def current
  self
end

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


4841
4842
4843
4844
4845
4846
# File 'lib/puppet/pops/model/ast.rb', line 4841

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

#line_offsetsObject


4803
4804
4805
# File 'lib/puppet/pops/model/ast.rb', line 4803

def line_offsets
  @locator.line_index
end

#source_refObject


4799
4800
4801
# File 'lib/puppet/pops/model/ast.rb', line 4799

def source_ref
  @locator.file
end

#source_textObject


4795
4796
4797
# File 'lib/puppet/pops/model/ast.rb', line 4795

def source_text
  @locator.string
end