Sha256: 81c7f95a056224019b39171aab879c19a8de67584a316e931ed60b50a4dd86c1
Contents?: true
Size: 835 Bytes
Versions: 41
Compression:
Stored size: 835 Bytes
Contents
# frozen_string_literal: true # ReplaceWithAction to replace code. class NodeMutation::ReplaceWithAction < NodeMutation::Action # The rewritten source code with proper indent. # # @return [String] rewritten code. def new_code if rewritten_source.include?("\n") new_code = [] rewritten_source.split("\n").each_with_index do |line, index| new_code << (index == 0 ? line : indent + line) end new_code.join("\n") else rewritten_source end end private # Calculate the begin the end positions. def calculate_position @start = NodeMutation.adapter.get_start(@node) @end = NodeMutation.adapter.get_end(@node) end # Indent of the node # # @return [String] n times whitesphace def indent ' ' * NodeMutation.adapter.get_start_loc(@node).column end end
Version data entries
41 entries across 41 versions & 1 rubygems