lib/bullet.rb in bullet-4.14.8 vs lib/bullet.rb in bullet-4.14.9
- old
+ new
@@ -14,10 +14,13 @@
autoload :Notification, 'bullet/notification'
autoload :Detector, 'bullet/detector'
autoload :Registry, 'bullet/registry'
autoload :NotificationCollector, 'bullet/notification_collector'
+ BULLET_DEBUG = 'BULLET_DEBUG'.freeze
+ TRUE = 'true'.freeze
+
if defined? Rails::Railtie
class BulletRailtie < Rails::Railtie
initializer "bullet.configure_rails_initialization" do |app|
app.middleware.use Bullet::Rack
end
@@ -72,22 +75,27 @@
def stacktrace_includes
@stacktrace_includes || []
end
def add_whitelist(options)
+ reset_whitelist
@whitelist[options[:type]][options[:class_name].classify] ||= []
@whitelist[options[:type]][options[:class_name].classify] << options[:association].to_sym
end
def get_whitelist_associations(type, class_name)
Array(@whitelist[type][class_name])
end
def reset_whitelist
- @whitelist = {:n_plus_one_query => {}, :unused_eager_loading => {}, :counter_cache => {}}
+ @whitelist ||= {:n_plus_one_query => {}, :unused_eager_loading => {}, :counter_cache => {}}
end
+ def clear_whitelist
+ @whitelist = nil
+ end
+
def bullet_logger=(active)
if active
require 'fileutils'
root_path = "#{rails? ? Rails.root.to_s : Dir.pwd}"
FileUtils.mkdir_p(root_path + '/log')
@@ -96,11 +104,11 @@
UniformNotifier.customized_logger = bullet_log_file
end
end
def debug(title, message)
- puts "[Bullet][#{title}] #{message}" if ENV['BULLET_DEBUG'] == 'true'
+ puts "[Bullet][#{title}] #{message}" if ENV[BULLET_DEBUG] == TRUE
end
def start_request
Thread.current[:bullet_start] = true
Thread.current[:bullet_notification_collector] = Bullet::NotificationCollector.new
@@ -130,10 +138,10 @@
Thread.current[:bullet_counter_possible_objects] = nil
Thread.current[:bullet_counter_impossible_objects] = nil
end
def start?
- Thread.current[:bullet_start]
+ enable? && Thread.current[:bullet_start]
end
def notification_collector
Thread.current[:bullet_notification_collector]
end