Class: Puppet::Pops::Model::SelectorExpression

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, selectors = _pcore_type['selectors'].value) ⇒ SelectorExpression

Returns a new instance of SelectorExpression.



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

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

Instance Attribute Details

#left_exprObject (readonly)



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

def left_expr
  @left_expr
end

#selectorsObject (readonly)



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

def selectors
  @selectors
end

Class Method Details

._pcore_typeObject



4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
# File 'lib/puppet/pops/model/ast.rb', line 4630

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

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



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

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

.from_asserted_hash(init_hash) ⇒ Object



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

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

.from_hash(init_hash) ⇒ Object



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

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



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

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
  @selectors.each do |value|
    block.call(value, path)
    value._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:



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

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

#_pcore_init_hashObject



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

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

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

Returns:

  • (Boolean)


4702
4703
4704
4705
4706
# File 'lib/puppet/pops/model/ast.rb', line 4702

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