| Class | Puppet::Parser::AST::CaseStatement |
| In: |
lib/puppet/parser/ast/casestatement.rb
|
| Parent: | AST::Branch |
The basic logical structure in Puppet. Supports a list of tests and statement arrays.
| default | [RW] | |
| options | [RW] | |
| test | [RW] |
# File lib/puppet/parser/ast/casestatement.rb, line 53
53: def each
54: [@test,@options].each { |child| yield child }
55: end
Short-curcuit evaluation. Return the value of the statements for the first option that matches.
# File lib/puppet/parser/ast/casestatement.rb, line 11
11: def evaluate(scope)
12: value = @test.safeevaluate(scope)
13: sensitive = Puppet[:casesensitive]
14: value = value.downcase if ! sensitive and value.respond_to?(:downcase)
15:
16: retvalue = nil
17: found = false
18:
19: # Iterate across the options looking for a match.
20: default = nil
21: @options.each { |option|
22: option.eachvalue(scope) { |opval|
23: opval = opval.downcase if ! sensitive and opval.respond_to?(:downcase)
24: if opval == value
25: found = true
26: break
27: end
28: }
29:
30: if found
31: # we found a matching option
32: retvalue = option.safeevaluate(scope)
33: break
34: end
35:
36: if option.default?
37: default = option
38: end
39: }
40:
41: # Unless we found something, look for the default.
42: unless found
43: if default
44: retvalue = default.safeevaluate(scope)
45: else
46: Puppet.debug "No true answers and no default"
47: retvalue = nil
48: end
49: end
50: return retvalue
51: end