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::Errors

#adderrorcontext, #devfail, #error_context, error_location, error_location_with_space, error_location_with_unknowns, #exceptwrap, #fail

Constructor Details

#initialize(hash) ⇒ Regex


53
54
55
56
57
# File 'lib/puppet/parser/ast/leaf.rb', line 53

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.


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

def evaluate(scope)
  self
end

#match(value) ⇒ Object


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

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

#to_sObject


77
78
79
# File 'lib/puppet/parser/ast/leaf.rb', line 77

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