diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-07-28 19:56:34 +0200 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-08-01 11:15:29 +1000 |
| commit | 3ebf148bf3d82d25e690aec6ec49975e0837e604 (patch) | |
| tree | b94504992e575d8b4181440b90bdf510cf67ef8c /lib/puppet/parser/ast/caseopt.rb | |
| parent | ef68967f2b72e609a9d69e53771a61fd9f522149 (diff) | |
| download | puppet-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.rb | 10 |
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) |
