Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbacks for specific notification #7

Closed
curpeng opened this issue Nov 1, 2019 · 4 comments
Closed

Callbacks for specific notification #7

curpeng opened this issue Nov 1, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@curpeng
Copy link
Contributor

curpeng commented Nov 1, 2019

Hi guys,

Thanks for implementing this gem, it's super helpful!
There is one thing, which seems to be really nice to have - an option to specify the name of the notification for a callback. It turned out that quite often, we need to do something only for specific notification. Right now, we have two options:

QuestionsDelivery < ApplicationDelivery
   after_notify :mark_question_as_sent 
  
   after_notify do
     # Option 2: check notification_name and call needed actions
      mark_question_as_sent if notification_name == :send_questions
      create_event if notification_name == :questions_reminder
   end

  private

  def mark_question_as_sent
    # Option 1: another notification doesn't need a question object, e.g. it's a reminder to a user that we can send questions, so we can just check if params[:question] is present. 
     return unless params[:question].present? 
  end
end

As you see, both solutions look hacky, it would be nice to have something like:

  after_notify :mark_question_as_sent, only: %[questions_sent]
@palkan palkan added the enhancement New feature or request label Nov 1, 2019
@palkan
Copy link
Owner

palkan commented Nov 1, 2019

Thanks for the suggestion. Sounds good to me.
Would you like to work on it yourself 🙂? My backlog is currently full, so I won't be able to take this until the end of December.

@curpeng
Copy link
Contributor Author

curpeng commented Nov 1, 2019

Sure thing, do you agree with the suggested API or you have other preferences? Are there any guides/requirements for PRs(e.g formatting)?

@palkan
Copy link
Owner

palkan commented Nov 1, 2019

Yep, except/only looks good to me.

Since we use ActiveSupport::Callbacks, we can take a look at how controllers callbacks are implemented: https://github.com/rails/rails/blob/master/actionpack/lib/abstract_controller/callbacks.rb.

I think, the similar approach would work for us (and, btw, this will also add support for if,unless and other options we do not support currently).

Are there any guides/requirements for PRs(e.g formatting)?

Nothing specific: write new code similarly to the one we already have, follow the code style (it's covered by RuboCop).

@palkan
Copy link
Owner

palkan commented Nov 7, 2019

Closed by #8

@palkan palkan closed this as completed Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants