Sha256: 19ce51b62ac4d783569e65033929521d575fe8100bf4fe80fd53f2e40f7b3206
Contents?: true
Size: 1.08 KB
Versions: 27
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module Synvert::Core # Action defines rewriter action, add, replace or remove code. class Rewriter::Action DEFAULT_INDENT = 2 # Initialize an action. # # @param instance [Synvert::Core::Rewriter::Instance] # @param code [String] new code to add, replace or remove. def initialize(instance, code) @instance = instance @code = code @node = @instance.current_node end # Line number of current node. # # @return [Integer] line number. def line @node.loc.expression.line end # The rewritten source code with proper indent. # # @return [String] rewritten code. def rewritten_code if rewritten_source.split("\n").length > 1 "\n\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }.join("\n") else "\n" + indent(@node) + rewritten_source end end # The rewritten source code. # # @return [String] rewritten source code. def rewritten_source @rewritten_source ||= @node.rewritten_source(@code) end end end
Version data entries
27 entries across 27 versions & 1 rubygems