lib/.rbnext/3.0/active_delivery/callbacks.rb in active_delivery-1.0.0.rc2 vs lib/.rbnext/3.0/active_delivery/callbacks.rb in active_delivery-1.0.0

- old
+ new

@@ -35,13 +35,15 @@ prepend InstanceExt singleton_class.prepend SingltonExt end module InstanceExt - def do_notify(...) - run_callbacks(:notify) { super(...) } - end; respond_to?(:ruby2_keywords, true) && (ruby2_keywords :do_notify) + def perform_notify(delivery, *__rest__, &__block__) + # We need to store the notification name to be able to use it in callbacks if/unless + @notification_name = delivery.notification + run_callbacks(:notify) { super(delivery, *__rest__, &__block__) } + end; respond_to?(:ruby2_keywords, true) && (ruby2_keywords :perform_notify) def notify_line(kind, *__rest__, &__block__) run_callbacks(kind) { super(kind, *__rest__, &__block__) } end; respond_to?(:ruby2_keywords, true) && (ruby2_keywords :notify_line) end @@ -71,25 +73,27 @@ define_callbacks name, terminator: CALLBACK_TERMINATOR, skip_after_callbacks_if_terminated: true end - def before_notify(method_or_block = nil, on: :notify, **options, &block) - method_or_block ||= block - _normalize_callback_options(options) - set_callback on, :before, method_or_block, options - end + %i[before after around].each do |kind| + define_method "#{kind}_notify" do |*names, on: :notify, **options, &block| + _normalize_callback_options(options) - def after_notify(method_or_block = nil, on: :notify, **options, &block) - method_or_block ||= block - _normalize_callback_options(options) - set_callback on, :after, method_or_block, options - end + names.each do |name| + set_callback on, kind, name, options + end - def around_notify(method_or_block = nil, on: :notify, **options, &block) - method_or_block ||= block - _normalize_callback_options(options) - set_callback on, :around, method_or_block, options + set_callback on, kind, block, options if block + end + + define_method "skip_#{kind}_notify" do |*names, on: :notify, **options| + _normalize_callback_options(options) + + names.each do |name| + skip_callback(on, kind, name, options) + end + end end end end end