Class: Puppet::Pops::Model::ApplyExpression

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, arguments = _pcore_type['arguments'].value, body = nil) ⇒ ApplyExpression

Returns a new instance of ApplyExpression.


2774
2775
2776
2777
2778
2779
# File 'lib/puppet/pops/model/ast.rb', line 2774

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

Instance Attribute Details

#argumentsObject (readonly)


2771
2772
2773
# File 'lib/puppet/pops/model/ast.rb', line 2771

def arguments
  @arguments
end

#bodyObject (readonly)


2772
2773
2774
# File 'lib/puppet/pops/model/ast.rb', line 2772

def body
  @body
end

Class Method Details

._pcore_typeObject


2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
# File 'lib/puppet/pops/model/ast.rb', line 2731

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::ApplyExpression', {
    'parent' => Expression._pcore_type,
    'attributes' => {
      'arguments' => {
        'type' => Types::PArrayType.new(Expression._pcore_type),
        'value' => []
      },
      'body' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      }
    }
  })
end

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


2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
# File 'lib/puppet/pops/model/ast.rb', line 2760

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

.from_asserted_hash(init_hash) ⇒ Object


2751
2752
2753
2754
2755
2756
2757
2758
# File 'lib/puppet/pops/model/ast.rb', line 2751

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

.from_hash(init_hash) ⇒ Object


2747
2748
2749
# File 'lib/puppet/pops/model/ast.rb', line 2747

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
# File 'lib/puppet/pops/model/ast.rb', line 2793

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

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

Yields:


2788
2789
2790
2791
# File 'lib/puppet/pops/model/ast.rb', line 2788

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

#_pcore_init_hashObject


2781
2782
2783
2784
2785
2786
# File 'lib/puppet/pops/model/ast.rb', line 2781

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

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

Returns:

  • (Boolean)

2806
2807
2808
2809
2810
# File 'lib/puppet/pops/model/ast.rb', line 2806

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