Sha256: 8a2bffa1ebf14d5ab53a75871fb982248288e4018a98873857184958076dfbce

Contents?: true

Size: 961 Bytes

Versions: 12

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  # ReplaceAction to replace child node with code.
  class Rewriter::ReplaceAction < Rewriter::Action
    # Initailize a ReplaceAction.
    #
    # @param instance [Synvert::Core::Rewriter::Instance]
    # @param selectors [Array<Symbol|String>] used to select child nodes
    # @param with [String] the new code
    def initialize(instance, *selectors, with:)
      super(instance, with)
      @selectors = selectors
    end

    # The rewritten source code.
    #
    # @return [String] rewritten code.
    def rewritten_code
      rewritten_source
    end

    private

    # Calculate the begin the end positions.
    def calculate_position
      @begin_pos = @selectors.map { |selector| @node.child_node_range(selector).begin_pos }
                             .min
      @end_pos = @selectors.map { |selector| @node.child_node_range(selector).end_pos }
                           .max
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
synvert-core-1.4.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.3.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.3.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.2.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.2.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.1.1 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.1.0 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.0.5 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.0.4 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.0.3 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.0.2 lib/synvert/core/rewriter/action/replace_action.rb
synvert-core-1.0.1 lib/synvert/core/rewriter/action/replace_action.rb