Class: Synvert::Core::Rewriter::Action
- Inherits:
-
Object
- Object
- Synvert::Core::Rewriter::Action
- Defined in:
- lib/synvert/core/rewriter/action.rb
Overview
Action defines rewriter action, insert, replace or delete code.
Direct Known Subclasses
AppendAction, DeleteAction, InsertAction, InsertAfterAction, PrependAction, RemoveAction, ReplaceAction, ReplaceErbStmtWithExprAction, ReplaceWithAction, WrapAction
Constant Summary collapse
- DEFAULT_INDENT =
2
Instance Attribute Summary collapse
-
#begin_pos ⇒ Integer
readonly
Begin position.
-
#end_pos ⇒ Object
readonly
Returns the value of attribute end_pos.
Instance Method Summary collapse
-
#initialize(instance, code) ⇒ Action
constructor
Initialize an action.
-
#process ⇒ Synvert::Core::Rewriter::Action
Calculate begin and end positions, and return self.
-
#rewritten_code ⇒ String
The rewritten source code with proper indent.
Constructor Details
#initialize(instance, code) ⇒ Action
Initialize an action.
18 19 20 21 22 |
# File 'lib/synvert/core/rewriter/action.rb', line 18 def initialize(instance, code) @instance = instance @code = code @node = @instance.current_node end |
Instance Attribute Details
#begin_pos ⇒ Integer (readonly)
Returns begin position.
12 13 14 |
# File 'lib/synvert/core/rewriter/action.rb', line 12 def begin_pos @begin_pos end |
#end_pos ⇒ Object (readonly)
Returns the value of attribute end_pos.
12 |
# File 'lib/synvert/core/rewriter/action.rb', line 12 attr_reader :begin_pos, :end_pos |
Instance Method Details
#process ⇒ Synvert::Core::Rewriter::Action
Calculate begin and end positions, and return self.
27 28 29 30 |
# File 'lib/synvert/core/rewriter/action.rb', line 27 def process calculate_position self end |
#rewritten_code ⇒ String
The rewritten source code with proper indent.
35 36 37 38 39 40 41 42 |
# File 'lib/synvert/core/rewriter/action.rb', line 35 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 |