module ActiveDelivery::Callbacks
Add callbacks support to Active Delivery (requires ActiveSupport::Callbacks)
# Run method before delivering notification # NOTE: when `false` is returned the executation is halted before_notify :do_something # You can specify a notification method (to run callback only for that method) before_notify :do_mail_something, on: :mail # or for push notifications before_notify :do_mail_something, on: :push # after_ and around_ callbacks are also supported after_notify :cleanup around_notify :set_context
Constants
- CALLBACK_TERMINATOR
Public Instance Methods
_normalize_callback_option(options, from, to)
click to toggle source
# File lib/active_delivery/callbacks.rb, line 66 def _normalize_callback_option(options, from, to) if (from = options[from]) from_set = Array(from).map(&:to_s).to_set from = proc { |c| from_set.include? c.notification_name.to_s } options[to] = Array(options[to]).unshift(from) end end
_normalize_callback_options(options)
click to toggle source
# File lib/active_delivery/callbacks.rb, line 61 def _normalize_callback_options(options) _normalize_callback_option(options, :only, :if) _normalize_callback_option(options, :except, :unless) end
after_notify(method_or_block = nil, on: :notify, **options, &block)
click to toggle source
# File lib/active_delivery/callbacks.rb, line 86 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
around_notify(method_or_block = nil, on: :notify, **options, &block)
click to toggle source
# File lib/active_delivery/callbacks.rb, line 92 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 end
before_notify(method_or_block = nil, on: :notify, **options, &block)
click to toggle source
# File lib/active_delivery/callbacks.rb, line 80 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
define_line_callbacks(name)
click to toggle source
# File lib/active_delivery/callbacks.rb, line 74 def define_line_callbacks(name) define_callbacks name, terminator: CALLBACK_TERMINATOR, skip_after_callbacks_if_terminated: true end