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.



3052
3053
3054
3055
3056
3057
3058
# File 'lib/puppet/pops/model/ast.rb', line 3052

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)



3050
3051
3052
# File 'lib/puppet/pops/model/ast.rb', line 3050

def else_expr
  @else_expr
end

#testObject (readonly)



3048
3049
3050
# File 'lib/puppet/pops/model/ast.rb', line 3048

def test
  @test
end

#then_exprObject (readonly)



3049
3050
3051
# File 'lib/puppet/pops/model/ast.rb', line 3049

def then_expr
  @then_expr
end

Class Method Details

._pcore_typeObject



3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
# File 'lib/puppet/pops/model/ast.rb', line 3005

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



3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
# File 'lib/puppet/pops/model/ast.rb', line 3036

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



3026
3027
3028
3029
3030
3031
3032
3033
3034
# File 'lib/puppet/pops/model/ast.rb', line 3026

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



3022
3023
3024
# File 'lib/puppet/pops/model/ast.rb', line 3022

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



3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
# File 'lib/puppet/pops/model/ast.rb', line 3074

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:



3068
3069
3070
3071
3072
# File 'lib/puppet/pops/model/ast.rb', line 3068

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



3060
3061
3062
3063
3064
3065
3066
# File 'lib/puppet/pops/model/ast.rb', line 3060

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)


3091
3092
3093
3094
3095
3096
# File 'lib/puppet/pops/model/ast.rb', line 3091

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