Sha256: 7be38a12e298ef9f563e4c206ea15d2d10c8d1da771cc044587fbd246cf5bca9

Contents?: true

Size: 742 Bytes

Versions: 13

Compression:

Stored size: 742 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  # AppendAction appends code to the bottom of node body.
  class Rewriter::AppendAction < Rewriter::Action
    private

    END_LENGTH = "\nend".length

    # Calculate the begin the end positions.
    def calculate_position
      @begin_pos = :begin == @node.type ? @node.loc.expression.end_pos : @node.loc.expression.end_pos - @node.column - END_LENGTH
      @end_pos = @begin_pos
    end

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

Version data entries

13 entries across 13 versions & 1 rubygems

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