Sha256: 4012cb9bebc3bc9218d36c52cff11f1ee698d9adbd49a7de349bf26f2a340cdd

Contents?: true

Size: 780 Bytes

Versions: 18

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true

# PrependAction to prepend code to the top of node body.
class NodeMutation::PrependAction < NodeMutation::Action
  private

  DO_LENGTH = ' do'.length

  # Calculate the begin and end positions.
  def calculate_position
    node_start = NodeMutation.adapter.get_start(@node)
    node_source = NodeMutation.adapter.get_source(@node)
    first_line = node_source.split("\n").first
    @start = first_line.end_with?("do") ? node_start + first_line.index("do") + "do".length : node_start + first_line.length
    @end = @start
  end

  # Indent of the node.
  #
  # @param node [Parser::AST::Node]
  # @return [String] n times whitesphace
  def indent(node)
    ' ' * (NodeMutation.adapter.get_start_loc(node).column + NodeMutation.tab_width)
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
node_mutation-1.15.2 lib/node_mutation/action/prepend_action.rb
node_mutation-1.15.1 lib/node_mutation/action/prepend_action.rb
node_mutation-1.15.0 lib/node_mutation/action/prepend_action.rb
node_mutation-1.14.0 lib/node_mutation/action/prepend_action.rb
node_mutation-1.13.2 lib/node_mutation/action/prepend_action.rb
node_mutation-1.13.1 lib/node_mutation/action/prepend_action.rb
node_mutation-1.13.0 lib/node_mutation/action/prepend_action.rb
node_mutation-1.12.3 lib/node_mutation/action/prepend_action.rb
node_mutation-1.12.2 lib/node_mutation/action/prepend_action.rb
node_mutation-1.12.1 lib/node_mutation/action/prepend_action.rb
node_mutation-1.12.0 lib/node_mutation/action/prepend_action.rb
node_mutation-1.11.0 lib/node_mutation/action/prepend_action.rb
node_mutation-1.10.1 lib/node_mutation/action/prepend_action.rb
node_mutation-1.10.0 lib/node_mutation/action/prepend_action.rb
node_mutation-1.9.3 lib/node_mutation/action/prepend_action.rb
node_mutation-1.9.2 lib/node_mutation/action/prepend_action.rb
node_mutation-1.9.1 lib/node_mutation/action/prepend_action.rb
node_mutation-1.9.0 lib/node_mutation/action/prepend_action.rb