Class: NodeMutation::IndentAction
- Defined in:
- lib/node_mutation/action/indent_action.rb
Overview
IndentAction to indent code.
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
-
#initialize(node, tab_size = 1, adapter:) ⇒ IndentAction
constructor
Initialize a IndentAction.
-
#new_code ⇒ String
The rewritten source code with proper indent.
Methods inherited from Action
Constructor Details
#initialize(node, tab_size = 1, adapter:) ⇒ IndentAction
Initialize a IndentAction.
10 11 12 13 14 |
# File 'lib/node_mutation/action/indent_action.rb', line 10 def initialize(node, tab_size = 1, adapter:) super(node, nil, adapter: adapter) @tab_size = tab_size @type = :replace end |
Instance Method Details
#new_code ⇒ String
The rewritten source code with proper indent.
19 20 21 22 23 |
# File 'lib/node_mutation/action/indent_action.rb', line 19 def new_code source = @adapter.get_source(@node) source.each_line.map { |line| (' ' * NodeMutation.tab_width * @tab_size) + line } .join end |