Class: NodeMutation::Action
- Inherits:
-
Object
- Object
- NodeMutation::Action
- Defined in:
- lib/node_mutation/action.rb
Overview
Action defines rewriter action, insert, replace or delete code.
Direct Known Subclasses
AppendAction, DeleteAction, GroupAction, IndentAction, InsertAction, NoopAction, PrependAction, RemoveAction, ReplaceAction, ReplaceWithAction
Instance Attribute Summary collapse
-
#actions ⇒ Array<NodeMutation::Action>
Child actions.
-
#end ⇒ Integer
End position.
-
#start ⇒ Integer
Start position.
-
#type ⇒ Symbol
Action type, :insert, :replace or :delete.
Instance Method Summary collapse
-
#initialize(node, code, adapter:) ⇒ Action
constructor
Initialize an action.
-
#process ⇒ NodeMutation::Action
Calculate begin and end positions, and return self.
- #to_struct ⇒ Object
Constructor Details
#initialize(node, code, adapter:) ⇒ Action
Initialize an action.
20 21 22 23 24 |
# File 'lib/node_mutation/action.rb', line 20 def initialize(node, code, adapter:) @node = node @code = code @adapter = adapter end |
Instance Attribute Details
#actions ⇒ Array<NodeMutation::Action>
Returns child actions.
13 |
# File 'lib/node_mutation/action.rb', line 13 attr_accessor :start, :end, :type, :actions |
#end ⇒ Integer
Returns end position.
13 |
# File 'lib/node_mutation/action.rb', line 13 attr_accessor :start, :end, :type, :actions |
#start ⇒ Integer
Returns start position.
13 14 15 |
# File 'lib/node_mutation/action.rb', line 13 def start @start end |
#type ⇒ Symbol
Returns action type, :insert, :replace or :delete.
13 |
# File 'lib/node_mutation/action.rb', line 13 attr_accessor :start, :end, :type, :actions |
Instance Method Details
#process ⇒ NodeMutation::Action
Calculate begin and end positions, and return self.
29 30 31 32 |
# File 'lib/node_mutation/action.rb', line 29 def process calculate_position self end |
#to_struct ⇒ Object
34 35 36 37 |
# File 'lib/node_mutation/action.rb', line 34 def to_struct to_struct_actions = @actions ? @actions.map(&:to_struct) : nil NodeMutation::Struct::Action.new(@type, @start, @end, new_code, to_struct_actions) end |