lib/bullet.rb in bullet-6.0.2 vs lib/bullet.rb in bullet-6.1.0

- old
+ new

@@ -21,41 +21,49 @@ autoload :NotificationCollector, 'bullet/notification_collector' BULLET_DEBUG = 'BULLET_DEBUG' TRUE = 'true' - if defined? Rails::Railtie + if defined?(Rails::Railtie) class BulletRailtie < Rails::Railtie initializer 'bullet.configure_rails_initialization' do |app| app.middleware.use Bullet::Rack end end end class << self - attr_writer :n_plus_one_query_enable, :unused_eager_loading_enable, :counter_cache_enable, :stacktrace_includes, :stacktrace_excludes + attr_writer :n_plus_one_query_enable, + :unused_eager_loading_enable, + :counter_cache_enable, + :stacktrace_includes, + :stacktrace_excludes, + :skip_html_injection attr_reader :whitelist - attr_accessor :add_footer, :orm_pathches_applied + attr_accessor :add_footer, :orm_patches_applied available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" } - available_notifiers << { to: UniformNotifier } - delegate(*available_notifiers) + available_notifiers_options = { to: UniformNotifier } + delegate(*available_notifiers, **available_notifiers_options) def raise=(should_raise) UniformNotifier.raise = (should_raise ? Notification::UnoptimizedQueryError : false) end - DETECTORS = [Bullet::Detector::NPlusOneQuery, - Bullet::Detector::UnusedEagerLoading, - Bullet::Detector::CounterCache].freeze + DETECTORS = [ + Bullet::Detector::NPlusOneQuery, + Bullet::Detector::UnusedEagerLoading, + Bullet::Detector::CounterCache + ].freeze def enable=(enable) @enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable + if enable? reset_whitelist - unless orm_pathches_applied - self.orm_pathches_applied = true + unless orm_patches_applied + self.orm_patches_applied = true Bullet::Mongoid.enable if mongoid? Bullet::ActiveRecord.enable if active_record? end end end @@ -172,13 +180,11 @@ notification_collector.notifications_present? end def gather_inline_notifications responses = [] - for_each_active_notifier_with_notification do |notification| - responses << notification.notify_inline - end + for_each_active_notifier_with_notification { |notification| responses << notification.notify_inline } responses.join("\n") end def perform_out_of_channel_notifications(env = {}) request_uri = build_request_uri(env) @@ -188,13 +194,11 @@ end end def footer_info info = [] - notification_collector.collection.each do |notification| - info << notification.short_notice - end + notification_collector.collection.each { |notification| info << notification.short_notice } info end def text_notifications info = [] @@ -212,10 +216,11 @@ end end def profile return_value = nil + if Bullet.enable? begin Bullet.start_request return_value = yield @@ -231,9 +236,13 @@ return_value end def console_enabled? UniformNotifier.active_notifiers.include?(UniformNotifier::JavascriptConsole) + end + + def skip_html_injection? + @skip_html_injection || false end private def for_each_active_notifier_with_notification