Sha256: 96c16e6e6d8d1c4b0e13dc199826a0389b57b006550b9d16ead77d33fdeb779f

Contents?: true

Size: 689 Bytes

Versions: 21

Compression:

Stored size: 689 Bytes

Contents

# frozen_string_literal: true

# AppendAction appends code to the bottom of node body.
class NodeMutation::AppendAction < NodeMutation::Action
  def initialize(node, code)
    super(node, code)
    @type = :insert
  end

  private

  END_LENGTH = "\nend".length

  # Calculate the begin the end positions.
  def calculate_position
    @start = NodeMutation.adapter.get_end(@node) - NodeMutation.adapter.get_start_loc(@node).column - END_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

21 entries across 21 versions & 1 rubygems

Version Path
node_mutation-1.21.6 lib/node_mutation/action/append_action.rb
node_mutation-1.21.5 lib/node_mutation/action/append_action.rb
node_mutation-1.21.4 lib/node_mutation/action/append_action.rb
node_mutation-1.21.3 lib/node_mutation/action/append_action.rb
node_mutation-1.21.2 lib/node_mutation/action/append_action.rb
node_mutation-1.21.1 lib/node_mutation/action/append_action.rb
node_mutation-1.21.0 lib/node_mutation/action/append_action.rb
node_mutation-1.20.0 lib/node_mutation/action/append_action.rb
node_mutation-1.19.4 lib/node_mutation/action/append_action.rb
node_mutation-1.19.3 lib/node_mutation/action/append_action.rb
node_mutation-1.19.2 lib/node_mutation/action/append_action.rb
node_mutation-1.19.1 lib/node_mutation/action/append_action.rb
node_mutation-1.19.0 lib/node_mutation/action/append_action.rb
node_mutation-1.18.3 lib/node_mutation/action/append_action.rb
node_mutation-1.18.2 lib/node_mutation/action/append_action.rb
node_mutation-1.18.1 lib/node_mutation/action/append_action.rb
node_mutation-1.18.0 lib/node_mutation/action/append_action.rb
node_mutation-1.17.1 lib/node_mutation/action/append_action.rb
node_mutation-1.17.0 lib/node_mutation/action/append_action.rb
node_mutation-1.16.0 lib/node_mutation/action/append_action.rb