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.



4385
4386
4387
4388
4389
4390
# File 'lib/puppet/pops/model/ast.rb', line 4385

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)



4382
4383
4384
# File 'lib/puppet/pops/model/ast.rb', line 4382

def left_expr
  @left_expr
end

#selectorsObject (readonly)



4383
4384
4385
# File 'lib/puppet/pops/model/ast.rb', line 4383

def selectors
  @selectors
end

Class Method Details

._pcore_typeObject



4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
# File 'lib/puppet/pops/model/ast.rb', line 4345

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



4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
# File 'lib/puppet/pops/model/ast.rb', line 4371

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



4362
4363
4364
4365
4366
4367
4368
4369
# File 'lib/puppet/pops/model/ast.rb', line 4362

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



4358
4359
4360
# File 'lib/puppet/pops/model/ast.rb', line 4358

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



4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
# File 'lib/puppet/pops/model/ast.rb', line 4404

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:



4399
4400
4401
4402
# File 'lib/puppet/pops/model/ast.rb', line 4399

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

#_pcore_init_hashObject



4392
4393
4394
4395
4396
4397
# File 'lib/puppet/pops/model/ast.rb', line 4392

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)


4417
4418
4419
4420
4421
# File 'lib/puppet/pops/model/ast.rb', line 4417

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