summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/leaf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/ast/leaf.rb')
-rw-r--r--lib/puppet/parser/ast/leaf.rb29
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 59bfc9e9d..1c1eae972 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -19,6 +19,10 @@ class Puppet::Parser::AST
obj == value
end
+ def match(value)
+ @value == value
+ end
+
def to_s
return @value.to_s unless @value.nil?
end
@@ -85,12 +89,12 @@ class Puppet::Parser::AST
# undef values; equiv to nil
class Undef < AST::Leaf; end
- # Host names, either fully qualified or just the short name
+ # Host names, either fully qualified or just the short name, or even a regex
class HostName < AST::Leaf
def initialize(hash)
super
- @value = @value.to_s.downcase
+ @value = @value.to_s.downcase unless @value.is_a?(Regex)
if @value =~ /[^-\w.]/
raise Puppet::DevError,
"'%s' is not a valid hostname" % @value
@@ -98,7 +102,9 @@ class Puppet::Parser::AST
end
def to_classname
- return @value
+ classname = @value.to_s.downcase
+ classname.gsub!(/[^-a-zA-Z0-9:.]/,'') if regex?
+ classname
end
# implementing eql? and hash so that when an HostName is stored
@@ -111,6 +117,19 @@ class Puppet::Parser::AST
def hash
return @value.hash
end
+
+ def match(value)
+ value = value.value if value.is_a?(HostName)
+ return @value.match(value)
+ end
+
+ def regex?
+ @value.is_a?(Regex)
+ end
+
+ def to_s
+ @value.to_s
+ end
end
# A simple variable. This object is only used during interpolation;
@@ -153,6 +172,10 @@ class Puppet::Parser::AST
matched
end
+ def match(value)
+ @value.match(value)
+ end
+
def to_s
return "/#{@value.source}/"
end