Class: Puppet::Parser::AST::Regex
- Defined in:
- lib/puppet/parser/ast/leaf.rb
Instance Attribute Summary
Attributes inherited from Leaf
Instance Method Summary collapse
-
#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.
- #evaluate_match(value, scope, options = {}) ⇒ Object
-
#initialize(hash) ⇒ Regex
constructor
A new instance of Regex.
- #match(value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ Regex
Returns a new instance of Regex.
182 183 184 185 |
# File 'lib/puppet/parser/ast/leaf.rb', line 182 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.
196 197 198 |
# File 'lib/puppet/parser/ast/leaf.rb', line 196 def evaluate(scope) self end |
#evaluate_match(value, scope, options = {}) ⇒ Object
200 201 202 203 204 205 206 207 |
# File 'lib/puppet/parser/ast/leaf.rb', line 200 def evaluate_match(value, scope, = {}) value = value == :undef ? '' : value.to_s if matched = @value.match(value) scope.ephemeral_from(matched, [:file], [:line]) end matched end |
#match(value) ⇒ Object
209 210 211 |
# File 'lib/puppet/parser/ast/leaf.rb', line 209 def match(value) @value.match(value) end |
#to_s ⇒ Object
213 214 215 |
# File 'lib/puppet/parser/ast/leaf.rb', line 213 def to_s "/#{@value.source}/" end |