Class: Puppet::Pops::Model::LambdaExpression

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, parameters = _pcore_type['parameters'].value, body = nil, return_type = nil) ⇒ LambdaExpression

Returns a new instance of LambdaExpression.


2682
2683
2684
2685
2686
2687
2688
# File 'lib/puppet/pops/model/ast.rb', line 2682

def initialize(locator, offset, length, parameters = _pcore_type['parameters'].value, body = nil, return_type = nil)
  super(locator, offset, length)
  @hash = @hash ^ parameters.hash ^ body.hash ^ return_type.hash
  @parameters = parameters
  @body = body
  @return_type = return_type
end

Instance Attribute Details

#bodyObject (readonly)


2679
2680
2681
# File 'lib/puppet/pops/model/ast.rb', line 2679

def body
  @body
end

#parametersObject (readonly)


2678
2679
2680
# File 'lib/puppet/pops/model/ast.rb', line 2678

def parameters
  @parameters
end

#return_typeObject (readonly)


2680
2681
2682
# File 'lib/puppet/pops/model/ast.rb', line 2680

def return_type
  @return_type
end

Class Method Details

._pcore_typeObject


2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
# File 'lib/puppet/pops/model/ast.rb', line 2632

def self._pcore_type
  @_pcore_type ||= Types::PObjectType.new('Puppet::AST::LambdaExpression', {
    'parent' => Expression._pcore_type,
    'attributes' => {
      'parameters' => {
        'type' => Types::PArrayType.new(Parameter._pcore_type),
        'value' => []
      },
      'body' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      },
      'return_type' => {
        'type' => Types::POptionalType.new(Expression._pcore_type),
        'value' => nil
      }
    }
  })
end

.create(locator, offset, length, parameters = _pcore_type['parameters'].value, body = nil, return_type = nil) ⇒ Object


2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
# File 'lib/puppet/pops/model/ast.rb', line 2666

def self.create(locator, offset, length, parameters = _pcore_type['parameters'].value, body = nil, return_type = nil)
  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::LambdaExpression[parameters]', attrs['parameters'].type, parameters)
  ta.assert_instance_of('Puppet::AST::LambdaExpression[body]', attrs['body'].type, body)
  ta.assert_instance_of('Puppet::AST::LambdaExpression[return_type]', attrs['return_type'].type, return_type)
  new(locator, offset, length, parameters, body, return_type)
end

.from_asserted_hash(init_hash) ⇒ Object


2656
2657
2658
2659
2660
2661
2662
2663
2664
# File 'lib/puppet/pops/model/ast.rb', line 2656

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

.from_hash(init_hash) ⇒ Object


2652
2653
2654
# File 'lib/puppet/pops/model/ast.rb', line 2652

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object


2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
# File 'lib/puppet/pops/model/ast.rb', line 2704

def _pcore_all_contents(path, &block)
  path << self
  @parameters.each do |value|
    block.call(value, path)
    value._pcore_all_contents(path, &block)
  end
  unless @body.nil?
    block.call(@body, path)
    @body._pcore_all_contents(path, &block)
  end
  unless @return_type.nil?
    block.call(@return_type, path)
    @return_type._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:


2698
2699
2700
2701
2702
# File 'lib/puppet/pops/model/ast.rb', line 2698

def _pcore_contents
  @parameters.each { |value| yield(value) }
  yield(@body) unless @body.nil?
  yield(@return_type) unless @return_type.nil?
end

#_pcore_init_hashObject


2690
2691
2692
2693
2694
2695
2696
# File 'lib/puppet/pops/model/ast.rb', line 2690

def _pcore_init_hash
  result = super
  result['parameters'] = @parameters unless _pcore_type['parameters'].default_value?(@parameters)
  result['body'] = @body unless @body == nil
  result['return_type'] = @return_type unless @return_type == nil
  result
end

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

Returns:

  • (Boolean)

2721
2722
2723
2724
2725
2726
# File 'lib/puppet/pops/model/ast.rb', line 2721

def eql?(o)
  super &&
  @parameters.eql?(o.parameters) &&
  @body.eql?(o.body) &&
  @return_type.eql?(o.return_type)
end