Module: PurchaseKit::Events
- Extended by:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/purchasekit/events.rb
Defined Under Namespace
Classes: Event
Constant Summary collapse
- TYPES =
%i[ subscription_created subscription_updated subscription_canceled subscription_expired ].freeze
Class Method Summary collapse
-
.publish(type, payload) ⇒ Event
Publish an event to all registered handlers.
Class Method Details
.publish(type, payload) ⇒ Event
Publish an event to all registered handlers.
Also publishes via ActiveSupport::Notifications for additional flexibility. Broadcasts redirect for subscription_created when Pay is not handling it.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/purchasekit/events.rb', line 22 def publish(type, payload) event = Event.new(type: type, payload: payload) # Call registered block handlers PurchaseKit.config.handlers_for(type).each do |handler| handler.call(event) end # Also publish via ActiveSupport::Notifications for subscribers ActiveSupport::Notifications.instrument("purchasekit.#{type}", event: event) # Broadcast redirect for new subscriptions (Pay handles its own broadcasts) if type == :subscription_created && !PurchaseKit.pay_enabled? broadcast_redirect(event) end event end |