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
- #calculate_position ⇒ Object
-
#initialize(instance, with:, indent: nil) ⇒ WrapAction
constructor
A new instance of WrapAction.
-
#rewritten_code ⇒ String
The rewritten source code.
Methods inherited from Action
Constructor Details
#initialize(instance, with:, indent: nil) ⇒ WrapAction
Returns a new instance of WrapAction.
9 10 11 12 |
# 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 |
Instance Method Details
#calculate_position ⇒ Object
14 15 16 17 |
# File 'lib/synvert/core/rewriter/action/wrap_action.rb', line 14 def calculate_position @begin_pos = @node.loc.expression.begin_pos @end_pos = @node.loc.expression.end_pos end |
#rewritten_code ⇒ String
The rewritten source code.
22 23 24 25 26 |
# 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 |