Method: NodeMutation#process

Defined in:
lib/node_mutation.rb

#processNodeMutation::Result

Process actions and return the new source.

If there’s an action range conflict, it will raise a ConflictActionError if strategy is set to THROW_ERROR, it will process all non conflicted actions and return ‘{ conflict: true }` if strategy is set to KEEP_RUNNING.



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/node_mutation.rb', line 258

def process
  @actions = optimize_group_actions(@actions)

  flatten_actions = flat_actions(@actions)
  if flatten_actions.length == 0
    return NodeMutation::Result.new(affected: false, conflicted: false)
  end

  @transform_proc.call(@actions) if @transform_proc
  sorted_actions = sort_flatten_actions(flatten_actions)
  conflict_actions = get_conflict_actions(sorted_actions)
  if conflict_actions.size > 0 && strategy?(Strategy::THROW_ERROR)
    raise ConflictActionError, "mutation actions are conflicted"
  end

  actions = sort_flatten_actions(flat_actions(get_filter_actions(conflict_actions)))
  new_source = rewrite_source(+@source, actions)
  result = NodeMutation::Result.new(affected: true, conflicted: !conflict_actions.empty?)
  result.new_source = new_source
  result
end