Class: Puppet::Parser::AST::Selector
- Inherits:
-
Branch
- Object
- Puppet::Parser::AST
- Branch
- Puppet::Parser::AST::Selector
- Defined in:
- lib/vendor/puppet/parser/ast/selector.rb
Overview
The inline conditional operator. Unlike CaseStatement, which executes code, we just return a value.
Constant Summary
Constants inherited from Puppet::Parser::AST
Constants included from Util::Docs
Instance Attribute Summary collapse
-
#param ⇒ Object
Returns the value of attribute param.
-
#values ⇒ Object
Returns the value of attribute values.
Attributes inherited from Branch
Attributes inherited from Puppet::Parser::AST
Attributes included from Util::Docs
Instance Method Summary collapse
- #each ⇒ Object
-
#evaluate(scope) ⇒ Object
Find the value that corresponds with the test.
- #to_s ⇒ Object
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
#param ⇒ Object
Returns the value of attribute param.
7 8 9 |
# File 'lib/vendor/puppet/parser/ast/selector.rb', line 7 def param @param end |
#values ⇒ Object
Returns the value of attribute values.
7 8 9 |
# File 'lib/vendor/puppet/parser/ast/selector.rb', line 7 def values @values end |
Instance Method Details
#each ⇒ Object
9 10 11 |
# File 'lib/vendor/puppet/parser/ast/selector.rb', line 9 def each [@param,@values].each { |child| yield child } end |
#evaluate(scope) ⇒ Object
Find the value that corresponds with the test.
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/selector.rb', line 14 def evaluate(scope) level = scope.ephemeral_level # Get our parameter. paramvalue = @param.safeevaluate(scope) default = nil @values = [@values] unless @values.instance_of? AST::ASTArray or @values.instance_of? Array # Then look for a match in the options. @values.each do |obj| # short circuit asap if we have a match return obj.value.safeevaluate(scope) if obj.param.evaluate_match(paramvalue, scope) # Store the default, in case it's necessary. default = obj if obj.param.is_a?(Default) end # Unless we found something, look for the default. return default.value.safeevaluate(scope) if default self.fail Puppet::ParseError, "No matching value for selector param '#{paramvalue}'" ensure scope.unset_ephemeral_var(level) end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/vendor/puppet/parser/ast/selector.rb', line 40 def to_s param.to_s + " ? { " + values.collect { |v| v.to_s }.join(', ') + " }" end |