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.


2862
2863
2864
2865
2866
2867
2868
# File 'lib/puppet/pops/model/ast.rb', line 2862

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)


2860
2861
2862
# File 'lib/puppet/pops/model/ast.rb', line 2860

def else_expr
  @else_expr
end

#testObject (readonly)


2858
2859
2860
# File 'lib/puppet/pops/model/ast.rb', line 2858

def test
  @test
end

#then_exprObject (readonly)


2859
2860
2861
# File 'lib/puppet/pops/model/ast.rb', line 2859

def then_expr
  @then_expr
end

Class Method Details

._pcore_typeObject


2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
# File 'lib/puppet/pops/model/ast.rb', line 2815

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


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

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


2836
2837
2838
2839
2840
2841
2842
2843
2844
# File 'lib/puppet/pops/model/ast.rb', line 2836

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


2832
2833
2834
# File 'lib/puppet/pops/model/ast.rb', line 2832

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


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

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:


2878
2879
2880
2881
2882
# File 'lib/puppet/pops/model/ast.rb', line 2878

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


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

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)

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

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