Class: Synvert::Core::Rewriter::WrapAction
- Defined in:
- lib/synvert/core/rewriter/action/wrap_action.rb
Overview
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.
Constant Summary
Constants inherited from Action
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
-
#initialize(instance, with:, indent: nil) ⇒ WrapAction
constructor
Initialize a WrapAction.
-
#rewritten_code ⇒ String
The rewritten source code.
Methods inherited from Action
Constructor Details
#initialize(instance, with:, indent: nil) ⇒ WrapAction
Initialize a WrapAction.
14 15 16 17 |
# File 'lib/synvert/core/rewriter/action/wrap_action.rb', line 14 def initialize(instance, with:, indent: nil) super(instance, with) @indent = indent || @node.column end |
Instance Method Details
#rewritten_code ⇒ String
The rewritten source code.
22 23 24 25 26 27 |
# File 'lib/synvert/core/rewriter/action/wrap_action.rb', line 22 def rewritten_code "#{@code}\n#{' ' * @indent}" + @node.to_source.split("\n").map { |line| " #{line}" } .join("\n") + "\n#{' ' * @indent}end" end |