Class: Synvert::Core::Rewriter::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/synvert/core/rewriter/condition.rb

Overview

Condition checks if nql or rules matches.

Direct Known Subclasses

IfExistCondition, UnlessExistCondition

Instance Method Summary collapse

Constructor Details

#initialize(instance, nql_or_rules) { ... } ⇒ Condition

Initialize a Condition.

Parameters:

Yields:

  • run when condition matches



11
12
13
14
15
# File 'lib/synvert/core/rewriter/condition.rb', line 11

def initialize(instance, nql_or_rules, &block)
  @instance = instance
  @node_query = NodeQuery.new(nql_or_rules, adapter: instance.current_parser)
  @block = block
end

Instance Method Details

#processObject

If condition matches, run the block code.



18
19
20
# File 'lib/synvert/core/rewriter/condition.rb', line 18

def process
  @instance.instance_eval(&@block) if match?
end