class
ActiveSupport::Subscriber
v8.1.1 -
Show latest stable
- Superclass: Object
Active Support Subscriber
+ActiveSupport::Subscriber+ is an object set to consume ActiveSupport::Notifications. The subscriber dispatches notifications to a registered object based on its given namespace.
An example would be an Active Record subscriber responsible for collecting statistics about queries:
module ActiveRecord class StatsSubscriber < ActiveSupport::Subscriber attach_to :active_record def sql(event) Statsd.timing("sql.#{event.payload[:name]}", event.duration) end end end
After configured, whenever a "sql.active_record" notification is published, it will properly dispatch the event (ActiveSupport::Notifications::Event) to the sql method.
We can detach a subscriber as well:
ActiveRecord::StatsSubscriber.detach_from(:active_record)
Attributes
| [R] | namespace |
| [R] | notifier |
| [R] | patterns |
| [R] | subscriber |
Files
- activesupport/lib/active_support/subscriber.rb