Class: Puppet::Pops::Model::AssignmentExpression

Inherits:
BinaryExpression show all
Defined in:
lib/puppet/pops/model/ast.rb

Instance Attribute Summary collapse

Attributes inherited from BinaryExpression

#left_expr, #right_expr

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, right_expr, operator) ⇒ AssignmentExpression

Returns a new instance of AssignmentExpression.



421
422
423
424
425
# File 'lib/puppet/pops/model/ast.rb', line 421

def initialize(locator, offset, length, left_expr, right_expr, operator)
  super(locator, offset, length, left_expr, right_expr)
  @hash = @hash ^ operator.hash
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)



419
420
421
# File 'lib/puppet/pops/model/ast.rb', line 419

def operator
  @operator
end

Class Method Details

._pcore_typeObject



383
384
385
386
387
388
389
390
391
# File 'lib/puppet/pops/model/ast.rb', line 383

def self._pcore_type
  @_pcore_type ||=
    Types::PObjectType.new('Puppet::AST::AssignmentExpression', {
                             'parent' => BinaryExpression._pcore_type,
                             'attributes' => {
                               'operator' => Types::PEnumType.new(['+=', '-=', '='])
                             }
                           })
end

.create(locator, offset, length, left_expr, right_expr, operator) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
# File 'lib/puppet/pops/model/ast.rb', line 407

def self.create(locator, offset, length, left_expr, right_expr, operator)
  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::BinaryExpression[left_expr]', attrs['left_expr'].type, left_expr)
  ta.assert_instance_of('Puppet::AST::BinaryExpression[right_expr]', attrs['right_expr'].type, right_expr)
  ta.assert_instance_of('Puppet::AST::AssignmentExpression[operator]', attrs['operator'].type, operator)
  new(locator, offset, length, left_expr, right_expr, operator)
end

.from_asserted_hash(init_hash) ⇒ Object



397
398
399
400
401
402
403
404
405
# File 'lib/puppet/pops/model/ast.rb', line 397

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['left_expr'],
    init_hash['right_expr'],
    init_hash['operator'])
end

.from_hash(init_hash) ⇒ Object



393
394
395
# File 'lib/puppet/pops/model/ast.rb', line 393

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/puppet/pops/model/ast.rb', line 438

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
  unless @right_expr.nil?
    block.call(@right_expr, path)
    @right_expr._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:



433
434
435
436
# File 'lib/puppet/pops/model/ast.rb', line 433

def _pcore_contents
  yield(@left_expr) unless @left_expr.nil?
  yield(@right_expr) unless @right_expr.nil?
end

#_pcore_init_hashObject



427
428
429
430
431
# File 'lib/puppet/pops/model/ast.rb', line 427

def _pcore_init_hash
  result = super
  result['operator'] = @operator
  result
end

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

Returns:

  • (Boolean)


451
452
453
454
# File 'lib/puppet/pops/model/ast.rb', line 451

def eql?(o)
  super &&
  @operator.eql?(o.operator)
end