class Synvert::Core::Rewriter::WrapAction
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.
Public Class Methods
new(instance, with:, indent: nil)
click to toggle source
Calls superclass method
Synvert::Core::Rewriter::Action::new
# File lib/synvert/core/rewriter/action/wrap_action.rb, line 9 def initialize(instance, with:, indent: nil) super(instance, with) @indent = indent || @node.column end
Public Instance Methods
begin_pos()
click to toggle source
Begin position of code to wrap.
@return [Integer] begin position.
# File lib/synvert/core/rewriter/action/wrap_action.rb, line 17 def begin_pos @node.loc.expression.begin_pos end
end_pos()
click to toggle source
End position of code to wrap.
@return [Integer] end position.
# File lib/synvert/core/rewriter/action/wrap_action.rb, line 24 def end_pos @node.loc.expression.end_pos end
rewritten_code()
click to toggle source
The rewritten source code.
@return [String] rewritten code.
# File lib/synvert/core/rewriter/action/wrap_action.rb, line 31 def rewritten_code "#{@code}\n#{' ' * @indent}" + @node.to_source.split("\n").map { |line| " #{line}" }.join("\n") + "\n#{' ' * @indent}end" end