Module: Bullet
- Extended by:
- Dependency
- Defined in:
- lib/bullet.rb,
lib/bullet/rack.rb,
lib/bullet/version.rb,
lib/bullet/detector.rb,
lib/bullet/registry.rb,
lib/bullet/mongoid4x.rb,
lib/bullet/mongoid5x.rb,
lib/bullet/mongoid6x.rb,
lib/bullet/mongoid7x.rb,
lib/bullet/mongoid8x.rb,
lib/bullet/mongoid9x.rb,
lib/bullet/active_job.rb,
lib/bullet/dependency.rb,
lib/bullet/ext/object.rb,
lib/bullet/ext/string.rb,
lib/bullet/notification.rb,
lib/bullet/detector/base.rb,
lib/bullet/registry/base.rb,
lib/bullet/active_record70.rb,
lib/bullet/active_record71.rb,
lib/bullet/active_record72.rb,
lib/bullet/active_record80.rb,
lib/bullet/active_record81.rb,
lib/bullet/registry/object.rb,
lib/bullet/notification/base.rb,
lib/bullet/stack_trace_filter.rb,
lib/bullet/registry/call_stack.rb,
lib/bullet/detector/association.rb,
lib/bullet/registry/association.rb,
lib/bullet/detector/counter_cache.rb,
lib/bullet/notification_collector.rb,
lib/bullet/detector/n_plus_one_query.rb,
lib/bullet/notification/counter_cache.rb,
lib/generators/bullet/install_generator.rb,
lib/bullet/detector/unused_eager_loading.rb,
lib/bullet/notification/n_plus_one_query.rb,
lib/bullet/notification/unused_eager_loading.rb
Defined Under Namespace
Modules: ActiveJob, ActiveRecord, Dependency, Detector, Ext, Generators, Mongoid, Notification, Registry, SaveWithBulletSupport, StackTraceFilter
Classes: BulletRailtie, NotificationCollector, Rack
Constant Summary
collapse
- DETECTORS =
[
Bullet::Detector::NPlusOneQuery,
Bullet::Detector::UnusedEagerLoading,
Bullet::Detector::CounterCache
].freeze
- VERSION =
'8.2.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Methods included from Dependency
active_record6_or_older?, active_record70?, active_record71?, active_record72?, active_record7?, active_record80?, active_record81?, active_record8?, active_record?, active_record_version, mongoid4x?, mongoid5x?, mongoid6x?, mongoid7x?, mongoid8x?, mongoid9x?, mongoid?, mongoid_version
Class Attribute Details
Returns the value of attribute add_footer.
44
45
46
|
# File 'lib/bullet.rb', line 44
def
@add_footer
end
|
.always_append_html_body ⇒ Object
Returns the value of attribute always_append_html_body.
44
45
46
|
# File 'lib/bullet.rb', line 44
def always_append_html_body
@always_append_html_body
end
|
.counter_cache_enable=(value) ⇒ Object
Sets the attribute counter_cache_enable
37
38
39
|
# File 'lib/bullet.rb', line 37
def counter_cache_enable=(value)
@counter_cache_enable = value
end
|
Returns the value of attribute footer_position.
44
45
46
|
# File 'lib/bullet.rb', line 44
def
@footer_position
end
|
.n_plus_one_query_enable=(value) ⇒ Object
Sets the attribute n_plus_one_query_enable
37
38
39
|
# File 'lib/bullet.rb', line 37
def n_plus_one_query_enable=(value)
@n_plus_one_query_enable = value
end
|
.orm_patches_applied ⇒ Object
Returns the value of attribute orm_patches_applied.
44
45
46
|
# File 'lib/bullet.rb', line 44
def orm_patches_applied
@orm_patches_applied
end
|
.safelist ⇒ Object
Returns the value of attribute safelist.
43
44
45
|
# File 'lib/bullet.rb', line 43
def safelist
@safelist
end
|
.skip_html_injection=(value) ⇒ Object
Sets the attribute skip_html_injection
37
38
39
|
# File 'lib/bullet.rb', line 37
def skip_html_injection=(value)
@skip_html_injection = value
end
|
Returns the value of attribute skip_http_headers.
44
45
46
|
# File 'lib/bullet.rb', line 44
def
@skip_http_headers
end
|
.skip_user_in_notification ⇒ Object
Returns the value of attribute skip_user_in_notification.
44
45
46
|
# File 'lib/bullet.rb', line 44
def skip_user_in_notification
@skip_user_in_notification
end
|
.stacktrace_excludes ⇒ Object
109
110
111
|
# File 'lib/bullet.rb', line 109
def stacktrace_excludes
@stacktrace_excludes ||= []
end
|
.stacktrace_includes ⇒ Object
105
106
107
|
# File 'lib/bullet.rb', line 105
def stacktrace_includes
@stacktrace_includes ||= []
end
|
.unused_eager_loading_enable=(value) ⇒ Object
Sets the attribute unused_eager_loading_enable
37
38
39
|
# File 'lib/bullet.rb', line 37
def unused_eager_loading_enable=(value)
@unused_eager_loading_enable = value
end
|
Class Method Details
.add_safelist(options) ⇒ Object
113
114
115
116
117
|
# File 'lib/bullet.rb', line 113
def add_safelist(options)
reset_safelist
@safelist[options[:type]][options[:class_name]] ||= []
@safelist[options[:type]][options[:class_name]] << options[:association].to_sym
end
|
.app_root ⇒ Object
Rails.root might be nil if railties is a dependency on a project that does not use Rails
89
90
91
|
# File 'lib/bullet.rb', line 89
def app_root
@app_root ||= (defined?(::Rails.root) && !::Rails.root.nil? ? Rails.root.to_s : Dir.pwd).to_s
end
|
.bullet_logger=(active) ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'lib/bullet.rb', line 138
def bullet_logger=(active)
if active
require 'fileutils'
FileUtils.mkdir_p(app_root + '/log')
bullet_log_file = File.open("#{app_root}/log/bullet.log", 'a+')
bullet_log_file.sync = true
UniformNotifier.customized_logger = bullet_log_file
end
end
|
.clear_safelist ⇒ Object
134
135
136
|
# File 'lib/bullet.rb', line 134
def clear_safelist
@safelist = nil
end
|
.console_enabled? ⇒ Boolean
279
280
281
|
# File 'lib/bullet.rb', line 279
def console_enabled?
UniformNotifier.active_notifiers.include?(UniformNotifier::JavascriptConsole)
end
|
.counter_cache_enable? ⇒ Boolean
101
102
103
|
# File 'lib/bullet.rb', line 101
def counter_cache_enable?
enable? && (@counter_cache_enable.nil? ? true : @counter_cache_enable)
end
|
.debug(title, message) ⇒ Object
148
149
150
|
# File 'lib/bullet.rb', line 148
def debug(title, message)
puts "[Bullet][#{title}] #{message}" if ENV['BULLET_DEBUG'] == 'true'
end
|
.delete_safelist(options) ⇒ Object
119
120
121
122
123
124
|
# File 'lib/bullet.rb', line 119
def delete_safelist(options)
reset_safelist
@safelist[options[:type]][options[:class_name]] ||= []
@safelist[options[:type]][options[:class_name]].delete(options[:association].to_sym)
@safelist[options[:type]].delete_if { |_key, val| val.empty? }
end
|
.enable=(enable) ⇒ Object
Also known as:
enabled=
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/bullet.rb', line 67
def enable=(enable)
@enable = enable
if enable?
reset_safelist
unless orm_patches_applied
self.orm_patches_applied = true
Bullet::Mongoid.enable if mongoid?
Bullet::ActiveRecord.enable if active_record?
end
end
end
|
.enable? ⇒ Boolean
Also known as:
enabled?
82
83
84
|
# File 'lib/bullet.rb', line 82
def enable?
!!@enable
end
|
.end_request ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/bullet.rb', line 173
def end_request
Thread.current.thread_variable_set(:bullet_start, nil)
Thread.current.thread_variable_set(:bullet_notification_collector, nil)
Thread.current.thread_variable_set(:bullet_object_associations, nil)
Thread.current.thread_variable_set(:bullet_call_object_associations, nil)
Thread.current.thread_variable_set(:bullet_possible_objects, nil)
Thread.current.thread_variable_set(:bullet_impossible_objects, nil)
Thread.current.thread_variable_set(:bullet_inversed_objects, nil)
Thread.current.thread_variable_set(:bullet_eager_loadings, nil)
Thread.current.thread_variable_set(:bullet_counter_possible_objects, nil)
Thread.current.thread_variable_set(:bullet_counter_impossible_objects, nil)
end
|
237
238
239
240
241
|
# File 'lib/bullet.rb', line 237
def
info = []
notification_collector.collection.each { |notification| info << notification.short_notice }
info
end
|
.gather_inline_notifications ⇒ Object
223
224
225
226
227
|
# File 'lib/bullet.rb', line 223
def gather_inline_notifications
responses = []
for_each_active_notifier_with_notification { |notification| responses << notification.notify_inline }
responses.join("\n")
end
|
.get_safelist_associations(type, class_name) ⇒ Object
126
127
128
|
# File 'lib/bullet.rb', line 126
def get_safelist_associations(type, class_name)
Array.wrap(@safelist[type][class_name]).flat_map { |a| [a, a.to_s] }
end
|
.inject_into_page? ⇒ Boolean
287
288
289
290
291
|
# File 'lib/bullet.rb', line 287
def inject_into_page?
return false if defined?(@skip_html_injection) && @skip_html_injection
console_enabled? ||
end
|
.n_plus_one_query_enable? ⇒ Boolean
93
94
95
|
# File 'lib/bullet.rb', line 93
def n_plus_one_query_enable?
enable? && (@n_plus_one_query_enable.nil? ? true : @n_plus_one_query_enable)
end
|
.notification_collector ⇒ Object
212
213
214
|
# File 'lib/bullet.rb', line 212
def notification_collector
Thread.current.thread_variable_get(:bullet_notification_collector)
end
|
.pause ⇒ Object
192
193
194
|
# File 'lib/bullet.rb', line 192
def pause
Thread.current.thread_variable_set(:bullet_start, false)
end
|
.paused? ⇒ Boolean
200
201
202
|
# File 'lib/bullet.rb', line 200
def paused?
enable? && !Thread.current.thread_variable_get(:bullet_start)
end
|
229
230
231
232
233
234
235
|
# File 'lib/bullet.rb', line 229
def perform_out_of_channel_notifications(env = {})
request_uri = build_request_uri(env)
for_each_active_notifier_with_notification do |notification|
notification.url = request_uri
notification.notify_out_of_channel
end
end
|
.raise=(should_raise) ⇒ Object
.reset_safelist ⇒ Object
130
131
132
|
# File 'lib/bullet.rb', line 130
def reset_safelist
@safelist ||= { n_plus_one_query: {}, unused_eager_loading: {}, counter_cache: {} }
end
|
.resume ⇒ Object
196
197
198
|
# File 'lib/bullet.rb', line 196
def resume
Thread.current.thread_variable_set(:bullet_start, true)
end
|
.skip ⇒ Object
204
205
206
207
208
209
210
|
# File 'lib/bullet.rb', line 204
def skip
bullet_was_started = start?
pause if bullet_was_started
yield
ensure
resume if bullet_was_started
end
|
.start? ⇒ Boolean
188
189
190
|
# File 'lib/bullet.rb', line 188
def start?
enable? && Thread.current.thread_variable_get(:bullet_start)
end
|
.start_request ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/bullet.rb', line 152
def start_request
Thread.current.thread_variable_set(:bullet_start, true)
Thread.current.thread_variable_set(:bullet_notification_collector, Bullet::NotificationCollector.new)
Thread.current.thread_variable_set(:bullet_object_associations, Bullet::Registry::Base.new)
Thread.current.thread_variable_set(:bullet_call_object_associations, Bullet::Registry::Base.new)
Thread.current.thread_variable_set(:bullet_possible_objects, Bullet::Registry::Object.new)
Thread.current.thread_variable_set(:bullet_impossible_objects, Bullet::Registry::Object.new)
Thread.current.thread_variable_set(:bullet_inversed_objects, Bullet::Registry::Base.new)
Thread.current.thread_variable_set(:bullet_eager_loadings, Bullet::Registry::Association.new)
Thread.current.thread_variable_set(:bullet_call_stacks, Bullet::Registry::CallStack.new)
unless Thread.current.thread_variable_get(:bullet_counter_possible_objects)
Thread.current.thread_variable_set(:bullet_counter_possible_objects, Bullet::Registry::Object.new)
end
unless Thread.current.thread_variable_get(:bullet_counter_impossible_objects)
Thread.current.thread_variable_set(:bullet_counter_impossible_objects, Bullet::Registry::Object.new)
end
end
|
.text_notifications ⇒ Object
243
244
245
246
247
248
249
|
# File 'lib/bullet.rb', line 243
def text_notifications
info = []
notification_collector.collection.each do |notification|
info << notification.notification_data.values.compact.join("\n")
end
info
end
|
.unused_eager_loading_enable? ⇒ Boolean
97
98
99
|
# File 'lib/bullet.rb', line 97
def unused_eager_loading_enable?
enable? && (@unused_eager_loading_enable.nil? ? true : @unused_eager_loading_enable)
end
|
.warnings ⇒ Object
251
252
253
254
255
256
257
|
# File 'lib/bullet.rb', line 251
def warnings
notification_collector.collection.each_with_object({}) do |notification, warnings|
warning_type = notification.class.to_s.split(':').last.tableize
warnings[warning_type] ||= []
warnings[warning_type] << notification
end
end
|