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

Add StripeEvent.listening? #42

Merged
merged 1 commit into from
Oct 30, 2014
Merged

Add StripeEvent.listening? #42

merged 1 commit into from
Oct 30, 2014

Conversation

vandrijevik
Copy link
Contributor

Often, I find it helpful in my retrievers to know whether StripeEvent has any registered listeners for a particular event type. This allows me to avoid a Stripe::Event.retrieve API call to Stripe if I am not even interested in processing the event. Currently, I do this in my retrievers:

class StripeEventRetriever
  def call(params)
    return nil unless processing_events_of_type?(params[:type])
    # <snip>
  end

private
  def processing_events_of_type?(event_type)
    namespaced_type = StripeEvent.namespace.call(event_type)
    StripeEvent.backend.notifier.listening?(namespaced_type)
  end
end

Since StripeEvent.namespace and StripeEvent.backend are internal implementation details, I think it would be nice to provide a StripeEvent.listening? API which provides this functionality without exposing users of the gem to notification internals.

@invisiblefunnel
Copy link
Contributor

Thanks @vandrijevik. This looks great.

@peterkeen @rmm5t any thoughts?

@peterkeen
Copy link

I like it. 👍

invisiblefunnel added a commit that referenced this pull request Oct 30, 2014
@invisiblefunnel invisiblefunnel merged commit 563c60d into integrallis:master Oct 30, 2014
@vandrijevik vandrijevik deleted the va-add-listening-query branch October 30, 2014 16:41
@invisiblefunnel
Copy link
Contributor

Released 1.4.0. Thanks @vandrijevik @peterkeen.

@vandrijevik
Copy link
Contributor Author

Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants