Class: NodeMutation::InsertAction
- Defined in:
- lib/node_mutation/action/insert_action.rb
Overview
InsertAction to add code to the node.
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
-
#initialize(node, code, adapter:, at: 'end', to: nil, and_comma: false) ⇒ InsertAction
constructor
Initialize an InsertAction.
-
#new_code ⇒ String
The rewritten source code.
Methods inherited from Action
Constructor Details
#initialize(node, code, adapter:, at: 'end', to: nil, and_comma: false) ⇒ InsertAction
Initialize an InsertAction.
13 14 15 16 17 18 19 |
# File 'lib/node_mutation/action/insert_action.rb', line 13 def initialize(node, code, adapter:, at: 'end', to: nil, and_comma: false) super(node, code, adapter: adapter) @at = at @to = to @and_comma = and_comma @type = :insert end |
Instance Method Details
#new_code ⇒ String
The rewritten source code.
24 25 26 27 28 29 30 |
# File 'lib/node_mutation/action/insert_action.rb', line 24 def new_code if @and_comma @at == 'end' ? ", #{rewritten_source}" : "#{rewritten_source}, " else rewritten_source end end |