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

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

Constant Summary

Constants inherited from Puppet::Parser::AST

AST

Instance Attribute Summary

Attributes inherited from Leaf

#type, #value

Attributes inherited from Puppet::Parser::AST

#file, #line, #parent, #pos, #scope

Instance Method Summary collapse

Methods inherited from Puppet::Parser::AST

#inspect, #safeevaluate

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.



48
49
50
51
52
# File 'lib/puppet/parser/ast/leaf.rb', line 48

def initialize(hash)
  super
  # transform value from hash options unless it is already a regular expression
  @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.



64
65
66
# File 'lib/puppet/parser/ast/leaf.rb', line 64

def evaluate(scope)
  self
end

#match(value) ⇒ Object



68
69
70
# File 'lib/puppet/parser/ast/leaf.rb', line 68

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

#to_sObject



72
73
74
# File 'lib/puppet/parser/ast/leaf.rb', line 72

def to_s
  Puppet::Pops::Types::PRegexpType.regexp_to_s_with_delimiters(@value)
end