Sha256: f0ee09ecca9d27131722386c61e55304b694ae91e37a1ad527a0fe8e4cfa0b9f
Contents?: true
Size: 1.09 KB
Versions: 12
Compression:
Stored size: 1.09 KB
Contents
# frozen_string_literal: true module Synvert::Core # WrapAction to warp node within a block, class or module. # # Note: if WrapAction is conflicted with another action (begin_pos and end_pos are overlapped), # we have to put those 2 actions into 2 within_file scopes. class Rewriter::WrapAction < Rewriter::Action # Initialize a WrapAction. # # @param instance [Synvert::Core::Rewriter::WrapAction] # @param with [String] new code to wrap # @param indent [Integer, nil] number of whitespaces def initialize(instance, with:, indent: nil) super(instance, with) @indent = indent || @node.column end # The rewritten source code. # # @return [String] rewritten code. def rewritten_code "#{@code}\n#{' ' * @indent}" + @node.to_source.split("\n").map { |line| " #{line}" } .join("\n") + "\n#{' ' * @indent}end" end private # Calculate the begin the end positions. def calculate_position @begin_pos = @node.loc.expression.begin_pos @end_pos = @node.loc.expression.end_pos end end end
Version data entries
12 entries across 12 versions & 1 rubygems