diff --git a/lib/sequencer/unit/import/common/model/mixin/without_callback.rb b/lib/sequencer/unit/import/common/model/mixin/without_callback.rb new file mode 100644 index 000000000..27f9b0a83 --- /dev/null +++ b/lib/sequencer/unit/import/common/model/mixin/without_callback.rb @@ -0,0 +1,55 @@ +class Sequencer + class Unit + module Import + module Common + module Model + module Mixin + module WithoutCallback + module ClassMethods + + def without_callback(*callback) + @callbacks ||= [] + @callbacks.push(callback) + end + + def callbacks + Array(@callbacks) + end + end + + def self.prepended(base) + base.extend(ClassMethods) + base.uses :model_class + end + + def process + # keep the super call as the last or only entry point + entry_point = proc do + super + end + + # loop over all registerd callbacks + self.class.callbacks.each do |callback| + + # create a duplicate of the previous entry point + # to avoid an endless loop + previous_entry_point = entry_point.dup + + # replace the previous entry point with a wrapped version + # which skips the current callback + entry_point = proc do + model_class.without_callback(*callback, &previous_entry_point) + end + end + + # start at the last registerd entry point + # and go deep till we reach our super call + entry_point.call + end + end + end + end + end + end + end +end