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.



2872
2873
2874
2875
2876
2877
2878
# File 'lib/puppet/pops/model/ast.rb', line 2872

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)



2869
2870
2871
# File 'lib/puppet/pops/model/ast.rb', line 2869

def body
  @body
end

#parametersObject (readonly)



2868
2869
2870
# File 'lib/puppet/pops/model/ast.rb', line 2868

def parameters
  @parameters
end

#return_typeObject (readonly)



2870
2871
2872
# File 'lib/puppet/pops/model/ast.rb', line 2870

def return_type
  @return_type
end

Class Method Details

._pcore_typeObject



2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
# File 'lib/puppet/pops/model/ast.rb', line 2822

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



2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
# File 'lib/puppet/pops/model/ast.rb', line 2856

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



2846
2847
2848
2849
2850
2851
2852
2853
2854
# File 'lib/puppet/pops/model/ast.rb', line 2846

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



2842
2843
2844
# File 'lib/puppet/pops/model/ast.rb', line 2842

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



2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
# File 'lib/puppet/pops/model/ast.rb', line 2894

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:



2888
2889
2890
2891
2892
# File 'lib/puppet/pops/model/ast.rb', line 2888

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

#_pcore_init_hashObject



2880
2881
2882
2883
2884
2885
2886
# File 'lib/puppet/pops/model/ast.rb', line 2880

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)


2911
2912
2913
2914
2915
2916
# File 'lib/puppet/pops/model/ast.rb', line 2911

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