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

Constructor Details

#initialize(locator, offset, length, test, then_expr = nil, else_expr = nil) ⇒ IfExpression

Returns a new instance of IfExpression.



2929
2930
2931
2932
2933
2934
2935
# File 'lib/puppet/pops/model/ast.rb', line 2929

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)



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

def else_expr
  @else_expr
end

#testObject (readonly)



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

def test
  @test
end

#then_exprObject (readonly)



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

def then_expr
  @then_expr
end

Class Method Details

._pcore_typeObject



2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
# File 'lib/puppet/pops/model/ast.rb', line 2882

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



2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
# File 'lib/puppet/pops/model/ast.rb', line 2913

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



2903
2904
2905
2906
2907
2908
2909
2910
2911
# File 'lib/puppet/pops/model/ast.rb', line 2903

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



2899
2900
2901
# File 'lib/puppet/pops/model/ast.rb', line 2899

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



2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
# File 'lib/puppet/pops/model/ast.rb', line 2951

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:



2945
2946
2947
2948
2949
# File 'lib/puppet/pops/model/ast.rb', line 2945

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



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

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)


2968
2969
2970
2971
2972
2973
# File 'lib/puppet/pops/model/ast.rb', line 2968

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