Class: NodeMutation::AppendAction
- Defined in:
- lib/node_mutation/action/append_action.rb
Overview
AppendAction appends code to the bottom of node body.
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
-
#initialize(node, code, adapter:) ⇒ AppendAction
constructor
Initialize an AppendAction.
-
#new_code ⇒ String
The rewritten source code with proper indent.
Methods inherited from Action
Constructor Details
#initialize(node, code, adapter:) ⇒ AppendAction
Initialize an AppendAction.
10 11 12 13 |
# File 'lib/node_mutation/action/append_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/append_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 |