Class: Puppet::Pops::Model::AccessExpression

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, left_expr, keys = _pcore_type['keys'].value) ⇒ AccessExpression

Returns a new instance of AccessExpression.



653
654
655
656
657
658
# File 'lib/puppet/pops/model/ast.rb', line 653

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

Instance Attribute Details

#keysObject (readonly)



651
652
653
# File 'lib/puppet/pops/model/ast.rb', line 651

def keys
  @keys
end

#left_exprObject (readonly)



650
651
652
# File 'lib/puppet/pops/model/ast.rb', line 650

def left_expr
  @left_expr
end

Class Method Details

._pcore_typeObject



611
612
613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/puppet/pops/model/ast.rb', line 611

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

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



639
640
641
642
643
644
645
646
647
648
# File 'lib/puppet/pops/model/ast.rb', line 639

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

.from_asserted_hash(init_hash) ⇒ Object



630
631
632
633
634
635
636
637
# File 'lib/puppet/pops/model/ast.rb', line 630

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

.from_hash(init_hash) ⇒ Object



626
627
628
# File 'lib/puppet/pops/model/ast.rb', line 626

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



672
673
674
675
676
677
678
679
680
681
682
683
# File 'lib/puppet/pops/model/ast.rb', line 672

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

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

Yields:



667
668
669
670
# File 'lib/puppet/pops/model/ast.rb', line 667

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

#_pcore_init_hashObject



660
661
662
663
664
665
# File 'lib/puppet/pops/model/ast.rb', line 660

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

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

Returns:

  • (Boolean)


685
686
687
688
689
# File 'lib/puppet/pops/model/ast.rb', line 685

def eql?(o)
  super &&
  @left_expr.eql?(o.left_expr) &&
  @keys.eql?(o.keys)
end