Sha256: 68dcda914353f81d4802a2c5c5bc43bf3d6fbf5edf114a2cef955b0793b3db12
Contents?: true
Size: 808 Bytes
Versions: 45
Compression:
Stored size: 808 Bytes
Contents
# frozen_string_literal: true module Synvert::Core # Condition checks if nql or rules matches. class Rewriter::Condition # Initialize a Condition. # # @param instance [Synvert::Core::Rewriter::Instance] # @param nql_or_rules [String|Hash] # @yield run when condition matches def initialize(instance, nql_or_rules, &block) @instance = instance @node_query = NodeQuery.new(nql_or_rules) @block = block end # If condition matches, run the block code. def process @instance.instance_eval(&@block) if match? end protected # Check if condition matches # # @abstract def match? raise NotImplementedError, 'must be implemented by subclasses' end def target_node @instance.current_node end end end
Version data entries
45 entries across 45 versions & 1 rubygems