class Subscriber
Ruby on Rails 7.0.10
Since v4.0.13ActiveSupport::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)
Inherits from
Attributes
Methods (defined here)
- # finish
- # start
- self. attach_to
- self. detach_from
- self. method_added
- self. new
- self. subscribers
Private methods
(8)
Implementation detail — not part of the public API.
- # event_stack
- self. add_event_subscriber
- self. fetch_public_methods
- self. find_attached_subscriber
- self. invalid_event?
- self. pattern_subscribed?
- self. prepare_pattern
- self. remove_event_subscriber
Methods (inherited)
From Object (16)
- # acts_like?
- # blank?
- # deep_dup
- # duplicable?
- # html_safe?
- # in?
- # instance_values
- # instance_variable_names
- # presence
- # presence_in
- # present?
- # to_param
- # to_query
- # try
- # try!
- # with_options
From ActiveRecord::TestFixtures (4)
From ActiveSupport::Concern (3)
- # class_methods
- # included
- # prepended