| Class | Puppet::Parser::AST::Selector |
| In: |
lib/puppet/parser/ast/selector.rb
|
| Parent: | AST::Branch |
The inline conditional operator. Unlike CaseStatement, which executes code, we just return a value.
| param | [RW] | |
| values | [RW] |
# File lib/puppet/parser/ast/selector.rb, line 9
9: def each
10: [@param,@values].each { |child| yield child }
11: end
Find the value that corresponds with the test.
# File lib/puppet/parser/ast/selector.rb, line 14
14: def evaluate(scope)
15: retvalue = nil
16: found = nil
17:
18: # Get our parameter.
19: paramvalue = @param.safeevaluate(scope)
20:
21: sensitive = Puppet[:casesensitive]
22:
23: if ! sensitive and paramvalue.respond_to?(:downcase)
24: paramvalue = paramvalue.downcase
25: end
26:
27: default = nil
28:
29: unless @values.instance_of? AST::ASTArray or @values.instance_of? Array
30: @values = [@values]
31: end
32:
33: # Then look for a match in the options.
34: @values.each { |obj|
35: param = obj.param.safeevaluate(scope)
36: if ! sensitive && param.respond_to?(:downcase)
37: param = param.downcase
38: end
39: if param == paramvalue
40: # we found a matching option
41: retvalue = obj.value.safeevaluate(scope)
42: found = true
43: break
44: elsif obj.param.is_a?(Default)
45: # Store the default, in case it's necessary.
46: default = obj
47: end
48: }
49:
50: # Unless we found something, look for the default.
51: unless found
52: if default
53: retvalue = default.value.safeevaluate(scope)
54: else
55: self.fail Puppet::ParseError,
56: "No matching value for selector param '%s'" % paramvalue
57: end
58: end
59:
60: return retvalue
61: end