lib/node_mutation.rb in node_mutation-1.13.2 vs lib/node_mutation.rb in node_mutation-1.14.0

- old
+ new

@@ -20,12 +20,18 @@ autoload :NoopAction, 'node_mutation/action/noop_action' autoload :Result, 'node_mutation/result' autoload :Strategy, 'node_mutation/strategy' autoload :Struct, 'node_mutation/struct' + # @!attribute [r] actions + # @return [Array<NodeMutation::Struct::Action>] attr_reader :actions + # @!attribute [rw] transform_proc + # @return [Proc] proc to transfor the actions + attr_accessor :transform_proc + class << self # Configure NodeMutation # @param [Hash] options options to configure # @option options [NodeMutation::Adapter] :adapter the adpater # @option options [NodeMutation::Strategy] :strategy the strategy @@ -217,10 +223,11 @@ if @actions.length == 0 return NodeMutation::Result.new(affected: false, conflicted: false) end source = +@source + @transform_proc.call(@actions) if @transform_proc @actions.sort_by! { |action| [action.start, action.end] } conflict_actions = get_conflict_actions if conflict_actions.size > 0 && strategy?(Strategy::THROW_ERROR) raise ConflictActionError, "mutation actions are conflicted" end @@ -243,9 +250,10 @@ def test if @actions.length == 0 return NodeMutation::Result.new(affected: false, conflicted: false) end + @transform_proc.call(@actions) if @transform_proc @actions.sort_by! { |action| [action.start, action.end] } conflict_actions = get_conflict_actions if conflict_actions.size > 0 && strategy?(Strategy::THROW_ERROR) raise ConflictActionError, "mutation actions are conflicted" end