Class: Puppet::Parser::AST::CaseStatement
- Inherits:
-
Branch
- Object
- Puppet::Parser::AST
- Branch
- Puppet::Parser::AST::CaseStatement
- Defined in:
- lib/vendor/puppet/parser/ast/casestatement.rb
Overview
The basic logical structure in Puppet. Supports a list of tests and statement arrays.
Constant Summary
Constants inherited from Puppet::Parser::AST
Constants included from Util::Docs
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#options ⇒ Object
Returns the value of attribute options.
-
#test ⇒ Object
Returns the value of attribute test.
Attributes inherited from Branch
Attributes inherited from Puppet::Parser::AST
Attributes included from Util::Docs
Instance Method Summary collapse
- #each ⇒ Object
-
#evaluate(scope) ⇒ Object
Short-curcuit evaluation.
Methods inherited from Branch
Methods inherited from Puppet::Parser::AST
associates_doc, #evaluate_match, #initialize, #inspect, #parsefail, #parsewrap, #safeevaluate, settor?, #use_docs
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Constructor Details
This class inherits a constructor from Puppet::Parser::AST::Branch
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
7 8 9 |
# File 'lib/vendor/puppet/parser/ast/casestatement.rb', line 7 def default @default end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/vendor/puppet/parser/ast/casestatement.rb', line 7 def @options end |
#test ⇒ Object
Returns the value of attribute test.
7 8 9 |
# File 'lib/vendor/puppet/parser/ast/casestatement.rb', line 7 def test @test end |
Instance Method Details
#each ⇒ Object
40 41 42 |
# File 'lib/vendor/puppet/parser/ast/casestatement.rb', line 40 def each [@test,@options].each { |child| yield child } end |
#evaluate(scope) ⇒ Object
Short-curcuit evaluation. Return the value of the statements for the first option that matches.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vendor/puppet/parser/ast/casestatement.rb', line 13 def evaluate(scope) level = scope.ephemeral_level value = @test.safeevaluate(scope) retvalue = nil found = false # Iterate across the options looking for a match. default = nil @options.each do |option| option.eachopt do |opt| return option.safeevaluate(scope) if opt.evaluate_match(value, scope) end default = option if option.default? end # Unless we found something, look for the default. return default.safeevaluate(scope) if default Puppet.debug "No true answers and no default" return nil ensure scope.unset_ephemeral_var(level) end |