Sha256: d681126cde4a5c2b087ee108aa594eaf0b2b15c49f95bc64b2d415c4e6ddfb4b

Contents?: true

Size: 740 Bytes

Versions: 4

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  # AddAction to add code to the node.
  class Rewriter::InsertAction < Rewriter::Action
    def initialize(instance, code, at:)
      super(instance, code)
      @at = at
    end

    # Begin position to insert code.
    #
    # @return [Integer] begin position.
    def begin_pos
      if @at == 'end'
        @node.loc.expression.end_pos
      else
        @node.loc.expression.begin_pos
      end
    end

    # End position, always same to begin position.
    #
    # @return [Integer] end position.
    def end_pos
      begin_pos
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
synvert-core-0.53.0 lib/synvert/core/rewriter/action/insert_action.rb
synvert-core-0.52.1 lib/synvert/core/rewriter/action/insert_action.rb
synvert-core-0.52.0 lib/synvert/core/rewriter/action/insert_action.rb
synvert-core-0.51.1 lib/synvert/core/rewriter/action/insert_action.rb