13
# evaluate ourselves, and match
14
def evaluate_match(value, scope, options = {})
15
obj = self.safeevaluate(scope)
16
if ! options[:sensitive] && obj.respond_to?(:downcase)
27
return @value.to_s unless @value.nil?
64
89
# undef values; equiv to nil
65
90
class Undef < AST::Leaf; end
67
# Host names, either fully qualified or just the short name
92
# Host names, either fully qualified or just the short name, or even a regex
68
93
class HostName < AST::Leaf
69
94
def initialize(hash)
72
unless @value =~ %r{^[0-9a-zA-Z\-]+(\.[0-9a-zA-Z\-]+)*$}
97
@value = @value.to_s.downcase unless @value.is_a?(Regex)
98
if @value =~ /[^-\w.]/
73
99
raise Puppet::DevError,
74
100
"'%s' is not a valid hostname" % @value
105
to_s.downcase.gsub(/[^-\w:.]/,'').sub(/^\.+/,'')
108
# implementing eql? and hash so that when an HostName is stored
109
# in a hash it has the same hashing properties as the underlying value
111
value = value.value if value.is_a?(HostName)
112
return @value.eql?(value)
120
return @value.match(value) unless value.is_a?(HostName)
122
if value.regex? and self.regex?
123
# Wow this is some sweet design; maybe a touch of refactoring
125
return value.value.value == self.value.value
126
elsif value.regex? # we know if the existing name is not a regex, it won't match a regex
129
# else, we could be either a regex or normal and it doesn't matter
130
return @value.match(value.value)
79
143
# A simple variable. This object is only used during interpolation;
155
class Regex < AST::Leaf
158
@value = Regexp.new(@value) unless @value.is_a?(Regexp)
161
# we're returning self here to wrap the regexp and to be used in places
162
# where a string would have been used, without modifying any client code.
163
# For instance, in many places we have the following code snippet:
164
# val = @val.safeevaluate(@scope)
165
# if val.match(otherval)
168
# this way, we don't have to modify this test specifically for handling
174
def evaluate_match(value, scope, options = {})
175
value = value.is_a?(String) ? value : value.to_s
177
if matched = @value.match(value)
178
scope.ephemeral_from(matched, options[:file], options[:line])
188
return "/#{@value.source}/"