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

Constructor Details

#initialize(locator, offset, length, left_expr, selectors = _pcore_type['selectors'].value) ⇒ SelectorExpression

Returns a new instance of SelectorExpression.



4547
4548
4549
4550
4551
4552
# File 'lib/puppet/pops/model/ast.rb', line 4547

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)



4544
4545
4546
# File 'lib/puppet/pops/model/ast.rb', line 4544

def left_expr
  @left_expr
end

#selectorsObject (readonly)



4545
4546
4547
# File 'lib/puppet/pops/model/ast.rb', line 4545

def selectors
  @selectors
end

Class Method Details

._pcore_typeObject



4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
# File 'lib/puppet/pops/model/ast.rb', line 4507

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



4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
# File 'lib/puppet/pops/model/ast.rb', line 4533

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



4524
4525
4526
4527
4528
4529
4530
4531
# File 'lib/puppet/pops/model/ast.rb', line 4524

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



4520
4521
4522
# File 'lib/puppet/pops/model/ast.rb', line 4520

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



4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
# File 'lib/puppet/pops/model/ast.rb', line 4566

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:



4561
4562
4563
4564
# File 'lib/puppet/pops/model/ast.rb', line 4561

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

#_pcore_init_hashObject



4554
4555
4556
4557
4558
4559
# File 'lib/puppet/pops/model/ast.rb', line 4554

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)


4579
4580
4581
4582
4583
# File 'lib/puppet/pops/model/ast.rb', line 4579

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