lib/bullet.rb in bullet-4.6.0 vs lib/bullet.rb in bullet-4.7.0
- old
+ new
@@ -1,5 +1,6 @@
+require "active_support/core_ext/module/delegation"
require 'set'
require 'uniform_notifier'
require 'bullet/ext/object'
require 'bullet/ext/string'
require 'bullet/dependency'
@@ -8,11 +9,10 @@
extend Dependency
autoload :ActiveRecord, "bullet/#{active_record_version}" if active_record?
autoload :Mongoid, "bullet/#{mongoid_version}" if mongoid?
autoload :Rack, 'bullet/rack'
- autoload :BulletLogger, 'bullet/logger'
autoload :Notification, 'bullet/notification'
autoload :Detector, 'bullet/detector'
autoload :Registry, 'bullet/registry'
autoload :NotificationCollector, 'bullet/notification_collector'
@@ -22,16 +22,21 @@
app.middleware.use Bullet::Rack
end
end
end
- class <<self
+ class << self
attr_writer :enable, :n_plus_one_query_enable, :unused_eager_loading_enable, :counter_cache_enable
attr_reader :notification_collector, :whitelist
+ attr_accessor :add_footer
delegate :alert=, :console=, :growl=, :rails_logger=, :xmpp=, :airbrake=, :to => UniformNotifier
+ def raise=(should_raise)
+ UniformNotifier.raise=(should_raise ? Notification::UnoptimizedQueryError : false)
+ end
+
DETECTORS = [ Bullet::Detector::NPlusOneQuery,
Bullet::Detector::UnusedEagerLoading,
Bullet::Detector::CounterCache ]
def enable=(enable)
@@ -115,16 +120,35 @@
notification.url = [env['HTTP_HOST'], env['REQUEST_URI']].compact.join
notification.notify_out_of_channel
end
end
+ def footer_info
+ info = []
+ for_each_active_notifier_with_notification do |notification|
+ info << notification.short_notice
+ end
+ info
+ end
+
def warnings
notification_collector.collection.inject({}) do |warnings, notification|
warning_type = notification.class.to_s.split(':').last.tableize
warnings[warning_type] ||= []
warnings[warning_type] << notification
warnings
end
+ end
+
+ def profile
+ Bullet.start_request if Bullet.enable?
+
+ yield
+
+ if Bullet.enable? && Bullet.notification?
+ Bullet.perform_out_of_channel_notifications
+ end
+ Bullet.end_request if Bullet.enable?
end
private
def for_each_active_notifier_with_notification
UniformNotifier.active_notifiers.each do |notifier|