Class: NodeMutation::PrependAction
- Defined in:
- lib/node_mutation/action/prepend_action.rb
Overview
PrependAction to prepend code to the top of node body.
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
-
#initialize(node, code, adapter:) ⇒ PrependAction
constructor
Initialize an PrependAction.
-
#new_code ⇒ String
The rewritten source code with proper indent.
Methods inherited from Action
Constructor Details
#initialize(node, code, adapter:) ⇒ PrependAction
Initialize an PrependAction.
10 11 12 13 |
# File 'lib/node_mutation/action/prepend_action.rb', line 10 def initialize(node, code, adapter:) super(node, code, adapter: adapter) @type = :insert end |
Instance Method Details
#new_code ⇒ String
The rewritten source code with proper indent.
18 19 20 21 22 23 24 |
# File 'lib/node_mutation/action/prepend_action.rb', line 18 def new_code if rewritten_source.split("\n").length > 1 "\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }.join("\n") + "\n" else indent(@node) + rewritten_source + "\n" end end |