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

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

Constant Summary

Constants inherited from Puppet::Parser::AST

AST

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary

Attributes inherited from Leaf

#type, #value

Attributes inherited from Puppet::Parser::AST

#file, #line, #parent, #scope

Attributes included from Util::Docs

#doc, #nodoc

Instance Method Summary collapse

Methods inherited from Puppet::Parser::AST

associates_doc, #inspect, #parsefail, #parsewrap, #safeevaluate, settor?, #use_docs

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

#initialize(hash) ⇒ Regex

Returns a new instance of Regex.



186
187
188
189
# File 'lib/vendor/puppet/parser/ast/leaf.rb', line 186

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.



200
201
202
# File 'lib/vendor/puppet/parser/ast/leaf.rb', line 200

def evaluate(scope)
  self
end

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



204
205
206
207
208
209
210
211
# File 'lib/vendor/puppet/parser/ast/leaf.rb', line 204

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



213
214
215
# File 'lib/vendor/puppet/parser/ast/leaf.rb', line 213

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

#to_sObject



217
218
219
# File 'lib/vendor/puppet/parser/ast/leaf.rb', line 217

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