Class: Puppet::Parser::AST::Regex

Inherits:
Leaf show all
Defined in:
lib/puppet/parser/ast/leaf.rb

Instance Attribute Summary

Attributes inherited from Leaf

#type, #value

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Regex

Returns a new instance of Regex.



197
198
199
200
# File 'lib/puppet/parser/ast/leaf.rb', line 197

def initialize(hash)
  super
  @value = Regexp.new(@value) unless @value.is_a?(Regexp)
end

Instance Method Details

#evaluate(scope) ⇒ Object

we’re returning self here to wrap the regexp and to be used in places where a string would have been used, without modifying any client code. For instance, in many places we have the following code snippet:

val = @val.safeevaluate(@scope)
if val.match(otherval)
    ...
end

this way, we don’t have to modify this test specifically for handling regexes.



211
212
213
# File 'lib/puppet/parser/ast/leaf.rb', line 211

def evaluate(scope)
  self
end

#evaluate_match(value, scope, options = {}) ⇒ Object



215
216
217
218
219
220
221
222
# File 'lib/puppet/parser/ast/leaf.rb', line 215

def evaluate_match(value, scope, options = {})
  value = value == :undef ? '' : value.to_s

  if matched = @value.match(value)
    scope.ephemeral_from(matched, options[:file], options[:line])
  end
  matched
end

#match(value) ⇒ Object



224
225
226
# File 'lib/puppet/parser/ast/leaf.rb', line 224

def match(value)
  @value.match(value)
end

#to_sObject



228
229
230
# File 'lib/puppet/parser/ast/leaf.rb', line 228

def to_s
  "/#{@value.source}/"
end