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.



4483
4484
4485
4486
4487
4488
# File 'lib/puppet/pops/model/ast.rb', line 4483

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)



4480
4481
4482
# File 'lib/puppet/pops/model/ast.rb', line 4480

def left_expr
  @left_expr
end

#selectorsObject (readonly)



4481
4482
4483
# File 'lib/puppet/pops/model/ast.rb', line 4481

def selectors
  @selectors
end

Class Method Details

._pcore_typeObject



4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
# File 'lib/puppet/pops/model/ast.rb', line 4441

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



4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
# File 'lib/puppet/pops/model/ast.rb', line 4469

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



4460
4461
4462
4463
4464
4465
4466
4467
# File 'lib/puppet/pops/model/ast.rb', line 4460

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



4456
4457
4458
# File 'lib/puppet/pops/model/ast.rb', line 4456

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



4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
# File 'lib/puppet/pops/model/ast.rb', line 4502

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:



4497
4498
4499
4500
# File 'lib/puppet/pops/model/ast.rb', line 4497

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

#_pcore_init_hashObject



4490
4491
4492
4493
4494
4495
# File 'lib/puppet/pops/model/ast.rb', line 4490

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)


4515
4516
4517
4518
4519
# File 'lib/puppet/pops/model/ast.rb', line 4515

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