Sha256: 6135bcb832da1909e06d45eac6a54ef6e6f0c8ad229aa3a5af4b403f83644d24
Contents?: true
Size: 773 Bytes
Versions: 10
Compression:
Stored size: 773 Bytes
Contents
# frozen_string_literal: true module Synvert::Core # Condition checks if rules matches. class Rewriter::Condition # Initialize a Condition. # # @param instance [Synvert::Core::Rewriter::Instance] # @param rules [Hash] # @yield run when condition matches def initialize(instance, rules, &block) @instance = instance @node_query = NodeQuery.new(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
10 entries across 10 versions & 1 rubygems