Class: NodeMutation::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/node_mutation/action.rb

Overview

Action defines rewriter action, insert, replace or delete code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, code, adapter:) ⇒ Action

Initialize an action.

Parameters:



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

#actionsArray<NodeMutation::Action>

Returns child actions.

Returns:



13
# File 'lib/node_mutation/action.rb', line 13

attr_accessor :start, :end, :type, :actions

#endInteger

Returns end position.

Returns:

  • (Integer)

    end position



13
# File 'lib/node_mutation/action.rb', line 13

attr_accessor :start, :end, :type, :actions

#startInteger

Returns start position.

Returns:

  • (Integer)

    start position



13
14
15
# File 'lib/node_mutation/action.rb', line 13

def start
  @start
end

#typeSymbol

Returns action type, :insert, :replace or :delete.

Returns:

  • (Symbol)

    action type, :insert, :replace or :delete



13
# File 'lib/node_mutation/action.rb', line 13

attr_accessor :start, :end, :type, :actions

Instance Method Details

#processNodeMutation::Action

Calculate begin and end positions, and return self.

Returns:



29
30
31
32
# File 'lib/node_mutation/action.rb', line 29

def process
  calculate_position
  self
end

#to_structObject



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