Sha256: ec61061050267029f2aa29a993222d43481657594c7ac719218f0af34da7fe02
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 KB
Contents
require 'sweet_notifications/version' require 'sweet_notifications/log_subscriber' require 'sweet_notifications/controller_runtime' require 'sweet_notifications/railtie' # Syntactic sugar for ActiveSupport::Notifications subscribers for logging # purposes in Rails. module SweetNotifications extend ControllerRuntime extend Railtie # 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. # # @param name [Symbol] event namespace # @return [Rails::Railtie, ActiveSupport::LogSubscriber] An array consisting # of a Railtie and a LogSubscriber # @yield event subscription # # ==== Examples # # SweetNotifications.subscribe :active_record do # color ActiveSupport::LogSubscriber::GREEN # event :sql, runtime: true do |event| # return unless logger.debug? # debug message(event, event.payload[:name], event.payload[:sql]) # end # end def self.subscribe(name, &block) log_subscriber = Class.new(SweetNotifications::LogSubscriber, &block) controller_runtime = self.controller_runtime(name, 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sweet_notifications-0.1.0 | lib/sweet_notifications.rb |