summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/caseopt.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-07-28 19:56:34 +0200
committerJames Turnbull <james@lovedthanlost.net>2009-08-01 11:15:29 +1000
commit3ebf148bf3d82d25e690aec6ec49975e0837e604 (patch)
treeb94504992e575d8b4181440b90bdf510cf67ef8c /lib/puppet/parser/ast/caseopt.rb
parentef68967f2b72e609a9d69e53771a61fd9f522149 (diff)
downloadpuppet-3ebf148bf3d82d25e690aec6ec49975e0837e604.tar.gz
puppet-3ebf148bf3d82d25e690aec6ec49975e0837e604.tar.xz
puppet-3ebf148bf3d82d25e690aec6ec49975e0837e604.zip
Enhance selector and case statements to match with regexp
The case and selector statements define ephemeral vars, like 'if'. Usage: case statement: $var = "foobar" case $var { "foo": { notify { "got a foo": } } /(.*)bar$/: { notify{ "hey we got a $1": } } } and for selector: $val = $test ? { /^match.*$/ => "matched", default => "default" } Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser/ast/caseopt.rb')
-rw-r--r--lib/puppet/parser/ast/caseopt.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/caseopt.rb b/lib/puppet/parser/ast/caseopt.rb
index 824bde853..47f32e2ee 100644
--- a/lib/puppet/parser/ast/caseopt.rb
+++ b/lib/puppet/parser/ast/caseopt.rb
@@ -51,6 +51,16 @@ class Puppet::Parser::AST
end
end
+ def eachopt
+ if @value.is_a?(AST::ASTArray)
+ @value.each { |subval|
+ yield subval
+ }
+ else
+ yield @value
+ end
+ end
+
# Evaluate the actual statements; this only gets called if
# our option matched.
def evaluate(scope)