abstract_notifier icon indicating copy to clipboard operation
abstract_notifier copied to clipboard

Wrap around notification call similar to the around_action

Open dmitry opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

For the sake of easiness and reduce verbosity in mailers it's possible to set locale of current user like:

  before_action do
    if params
      @user = params[:user]
    end
  end

  around_action do
    I18n.with_locale(@user.locale, &block)
  end

I found there are no around wrappers in abstract notifier code.

Describe the solution you'd like

Would be nice to have similar ability to wrap some code around notification call, similar to the actionmailer.

Describe alternatives you've considered

Currently it's only possible to wrap public_send which calls notifications like so:

  def initialize(notification_name, user:, **params)
    @user = user
    super
  end

  def public_send(*)
    I18n.with_locale(@user.locale) do
      super
    end
  end

Additional context

Lets discuss and I'm able to provide a solution.

dmitry avatar Apr 21 '21 16:04 dmitry

Let's include callbacks support via ActiveSupport::Callbacks if this module is available similarly to what we do in ActiveDelivery: https://github.com/palkan/active_delivery/blob/master/lib/active_delivery/callbacks.rb

Would you like to propose a PR?

palkan avatar May 07 '21 13:05 palkan