Sha256: acb4947c99facc0bdef7e887e6eeed81ac9ca3575217b336e78c3508e853ee78

Contents?: true

Size: 831 Bytes

Versions: 15

Compression:

Stored size: 831 Bytes

Contents

# encoding: utf-8

module Synvert::Core
  # AppendWithAction to append code to the bottom of node body.
  class Rewriter::AppendAction < Rewriter::Action
    # Begin position to append code.
    #
    # @return [Integer] begin position.
    def begin_pos
      if :begin == @node.type
        @node.loc.expression.end_pos
      else
        @node.loc.expression.end_pos - @node.indent - 4
      end
    end

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

  private

    # Indent of the node.
    #
    # @param node [Parser::AST::Node]
    # @return [String] n times whitesphace
    def indent(node)
      if [:block, :class].include? node.type
        ' ' * (node.indent + 2)
      else
        ' ' * node.indent
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
synvert-core-0.15.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.15.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.14.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.13.2 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.13.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.13.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.12.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.11.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.11.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.10.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.9.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.9.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.8.2 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.8.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.8.0 lib/synvert/core/rewriter/action/append_action.rb