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.38.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.36.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.35.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.35.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.34.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.33.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.33.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.32.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.31.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.30.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.29.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.28.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.28.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.27.4 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.27.3 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.27.2 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.27.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.27.0 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.26.1 lib/synvert/core/rewriter/action/append_action.rb
synvert-core-0.26.0 lib/synvert/core/rewriter/action/append_action.rb