Sha256: 1b83513786143cc957a6f5df4a80c11404d8d6d233371b034486a4ca6ba2b395

Contents?: true

Size: 882 Bytes

Versions: 170

Compression:

Stored size: 882 Bytes

Contents

require 'puppet/parser/ast/branch'

class Puppet::Parser::AST
  # A basic 'if/elsif/else' statement.
  class IfStatement < AST::Branch

    associates_doc

    attr_accessor :test, :else, :statements

    def each
      [@test,@else,@statements].each { |child| yield child }
    end

    # Short-curcuit evaluation.  If we're true, evaluate our statements,
    # else if there's an 'else' setting, evaluate it.
    # the first option that matches.
    def evaluate(scope)
      level = scope.ephemeral_level
      value = @test.safeevaluate(scope)

      # let's emulate a new scope for each branches
      begin
        if Puppet::Parser::Scope.true?(value)
          return @statements.safeevaluate(scope)
        else
          return defined?(@else) ? @else.safeevaluate(scope) : nil
        end
      ensure
        scope.unset_ephemeral_var(level)
      end
    end
  end
end

Version data entries

170 entries across 170 versions & 5 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.7 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.7-x86-mingw32 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.7-x64-mingw32 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.6 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.6-x86-mingw32 lib/puppet/parser/ast/ifstatement.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.6-x64-mingw32 lib/puppet/parser/ast/ifstatement.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.5 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.5-x86-mingw32 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.5-x64-mingw32 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.4 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.4-x86-mingw32 lib/puppet/parser/ast/ifstatement.rb
puppet-3.8.4-x64-mingw32 lib/puppet/parser/ast/ifstatement.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/ifstatement.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/ifstatement.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/ifstatement.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/ifstatement.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/ast/ifstatement.rb