Sha256: f82a5b0219237d23698b48991fc34d2033e739ffb3f238440f2a8789e965becc

Contents?: true

Size: 895 Bytes

Versions: 52

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  # AppendAction to append code to the bottom of node body.
  class Rewriter::AppendAction < Rewriter::Action
    END_LENGTH = "\nend".length

    # 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 - END_LENGTH
      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 %i[block class].include? node.type
        ' ' * (node.indent + DEFAULT_INDENT)
      else
        ' ' * node.indent
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
synvert-core-0.51.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.51.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.50.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.49.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.49.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.48.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.47.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.46.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.45.2 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.45.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.45.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.44.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.44.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.42.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.42.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.41.2 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.41.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.41.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.40.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.39.0 lib/synvert/core/rewriter/action/append_action.rb