Class: Puppet::Pops::Model::IfExpression

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

Direct Known Subclasses

UnlessExpression

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, test, then_expr = nil, else_expr = nil) ⇒ IfExpression

Returns a new instance of IfExpression.



2924
2925
2926
2927
2928
2929
2930
# File 'lib/puppet/pops/model/ast.rb', line 2924

def initialize(locator, offset, length, test, then_expr = nil, else_expr = nil)
  super(locator, offset, length)
  @hash = @hash ^ test.hash ^ then_expr.hash ^ else_expr.hash
  @test = test
  @then_expr = then_expr
  @else_expr = else_expr
end

Instance Attribute Details

#else_exprObject (readonly)



2922
2923
2924
# File 'lib/puppet/pops/model/ast.rb', line 2922

def else_expr
  @else_expr
end

#testObject (readonly)



2920
2921
2922
# File 'lib/puppet/pops/model/ast.rb', line 2920

def test
  @test
end

#then_exprObject (readonly)



2921
2922
2923
# File 'lib/puppet/pops/model/ast.rb', line 2921

def then_expr
  @then_expr
end

Class Method Details

._pcore_typeObject



2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
# File 'lib/puppet/pops/model/ast.rb', line 2875

def self._pcore_type
  @_pcore_type ||=
    Types::PObjectType
      .new('Puppet::AST::IfExpression', {
             'parent' => Expression._pcore_type,
             'attributes' => {
               'test' => Expression._pcore_type,
               'then_expr' => {
                 'type' => Types::POptionalType.new(Expression._pcore_type),
                 'value' => nil
               },
               'else_expr' => {
                 'type' => Types::POptionalType.new(Expression._pcore_type),
                 'value' => nil
               }
             }
           })
end

.create(locator, offset, length, test, then_expr = nil, else_expr = nil) ⇒ Object



2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
# File 'lib/puppet/pops/model/ast.rb', line 2908

def self.create(locator, offset, length, test, then_expr = nil, else_expr = 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::IfExpression[test]', attrs['test'].type, test)
  ta.assert_instance_of('Puppet::AST::IfExpression[then_expr]', attrs['then_expr'].type, then_expr)
  ta.assert_instance_of('Puppet::AST::IfExpression[else_expr]', attrs['else_expr'].type, else_expr)
  new(locator, offset, length, test, then_expr, else_expr)
end

.from_asserted_hash(init_hash) ⇒ Object



2898
2899
2900
2901
2902
2903
2904
2905
2906
# File 'lib/puppet/pops/model/ast.rb', line 2898

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['test'],
    init_hash['then_expr'],
    init_hash['else_expr'])
end

.from_hash(init_hash) ⇒ Object



2894
2895
2896
# File 'lib/puppet/pops/model/ast.rb', line 2894

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

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
# File 'lib/puppet/pops/model/ast.rb', line 2946

def _pcore_all_contents(path, &block)
  path << self
  unless @test.nil?
    block.call(@test, path)
    @test._pcore_all_contents(path, &block)
  end
  unless @then_expr.nil?
    block.call(@then_expr, path)
    @then_expr._pcore_all_contents(path, &block)
  end
  unless @else_expr.nil?
    block.call(@else_expr, path)
    @else_expr._pcore_all_contents(path, &block)
  end
  path.pop
end

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

Yields:



2940
2941
2942
2943
2944
# File 'lib/puppet/pops/model/ast.rb', line 2940

def _pcore_contents
  yield(@test) unless @test.nil?
  yield(@then_expr) unless @then_expr.nil?
  yield(@else_expr) unless @else_expr.nil?
end

#_pcore_init_hashObject



2932
2933
2934
2935
2936
2937
2938
# File 'lib/puppet/pops/model/ast.rb', line 2932

def _pcore_init_hash
  result = super
  result['test'] = @test
  result['then_expr'] = @then_expr unless @then_expr == nil
  result['else_expr'] = @else_expr unless @else_expr == nil
  result
end

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

Returns:

  • (Boolean)


2963
2964
2965
2966
2967
2968
# File 'lib/puppet/pops/model/ast.rb', line 2963

def eql?(o)
  super &&
  @test.eql?(o.test) &&
  @then_expr.eql?(o.then_expr) &&
  @else_expr.eql?(o.else_expr)
end