Module: SweetNotifications
- Extended by:
- ControllerRuntime, Railtie
- Defined in:
- lib/sweet_notifications.rb,
lib/sweet_notifications/railtie.rb,
lib/sweet_notifications/version.rb,
lib/sweet_notifications/log_subscriber.rb,
lib/sweet_notifications/controller_runtime.rb
Overview
Syntactic sugar for ActiveSupport::Notifications subscribers for logging purposes in Rails.
Defined Under Namespace
Modules: ControllerRuntime, Railtie Classes: LogSubscriber
Constant Summary collapse
- VERSION =
'0.2.0'
Class Method Summary collapse
-
.subscribe(name, label: nil) { ... } ⇒ Rails::Railtie, ActiveSupport::LogSubscriber
Subscribe to an ActiveSupport::Notifications namespace.
Methods included from ControllerRuntime
Methods included from Railtie
Class Method Details
.subscribe(name, label: nil) { ... } ⇒ Rails::Railtie, ActiveSupport::LogSubscriber
Subscribe to an ActiveSupport::Notifications namespace.
This will subscribe to the namespace given as argument and, if necessary, create a Rails initializer that will be run when the application is initialized.
Examples
SweetNotifications.subscribe :active_record do
color ActiveSupport::LogSubscriber::GREEN
event :sql, runtime: true do |event|
return unless logger.debug?
debug (event, event.payload[:name], event.payload[:sql])
end
end
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sweet_notifications.rb', line 33 def self.subscribe(name, label: nil, &block) label ||= name log_subscriber = Class.new(SweetNotifications::LogSubscriber, &block) controller_runtime = self.controller_runtime(label, log_subscriber) if Rails.try(:application).try(:initialized?) initialize_rails(name, log_subscriber, controller_runtime) [nil, log_subscriber] else [railtie(name, log_subscriber, controller_runtime), log_subscriber] end end |