bullet 2.0.0.beta.2 → 2.0.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Hacking.textile +100 -0
- data/README.textile +36 -5
- data/README_for_rails2.textile +17 -0
- data/Rakefile +33 -16
- data/VERSION +1 -1
- data/autotest/discover.rb +1 -0
- data/bullet.gemspec +32 -9
- data/lib/bullet.rb +69 -38
- data/lib/bullet/action_controller2.rb +4 -4
- data/lib/bullet/active_record2.rb +16 -16
- data/lib/bullet/active_record3.rb +16 -25
- data/lib/bullet/detector.rb +9 -0
- data/lib/bullet/detector/association.rb +135 -0
- data/lib/bullet/detector/base.rb +19 -0
- data/lib/bullet/detector/counter.rb +43 -0
- data/lib/bullet/detector/n_plus_one_query.rb +39 -0
- data/lib/bullet/detector/unused_eager_association.rb +39 -0
- data/lib/bullet/notification.rb +4 -79
- data/lib/bullet/notification/base.rb +59 -0
- data/lib/bullet/notification/counter_cache.rb +13 -0
- data/lib/bullet/notification/n_plus_one_query.rb +32 -0
- data/lib/bullet/notification/unused_eager_loading.rb +14 -0
- data/lib/bullet/notification_collector.rb +25 -0
- data/lib/bullet/presenter.rb +13 -0
- data/lib/bullet/presenter/base.rb +9 -0
- data/lib/bullet/presenter/bullet_logger.rb +28 -0
- data/lib/bullet/presenter/growl.rb +40 -0
- data/lib/bullet/presenter/javascript_alert.rb +15 -0
- data/lib/bullet/presenter/javascript_console.rb +28 -0
- data/lib/bullet/presenter/javascript_helpers.rb +13 -0
- data/lib/bullet/presenter/rails_logger.rb +15 -0
- data/lib/bullet/presenter/xmpp.rb +56 -0
- data/lib/bullet/rack.rb +42 -0
- data/lib/bullet/registry.rb +7 -0
- data/lib/bullet/registry/association.rb +16 -0
- data/lib/bullet/registry/base.rb +39 -0
- data/lib/bullet/registry/object.rb +15 -0
- data/spec/bullet/association_for_chris_spec.rb +6 -6
- data/spec/bullet/association_for_peschkaj_spec.rb +6 -6
- data/spec/bullet/association_spec.rb +118 -262
- data/spec/bullet/counter_spec.rb +10 -10
- data/spec/spec_helper.rb +51 -17
- metadata +32 -9
- data/lib/bullet/association.rb +0 -294
- data/lib/bullet/counter.rb +0 -101
- data/lib/bullet/logger.rb +0 -9
- data/lib/bulletware.rb +0 -42
- data/spec/spec.opts +0 -3
data/lib/bullet/counter.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
module Bullet
|
2
|
-
class Counter
|
3
|
-
class <<self
|
4
|
-
include Bullet::Notification
|
5
|
-
|
6
|
-
def start_request
|
7
|
-
end
|
8
|
-
|
9
|
-
def end_request
|
10
|
-
clear
|
11
|
-
end
|
12
|
-
|
13
|
-
def clear
|
14
|
-
@@klazz_associations = nil
|
15
|
-
@@possible_objects = nil
|
16
|
-
@@impossible_objects = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def need_counter_caches?
|
20
|
-
!klazz_associations.empty?
|
21
|
-
end
|
22
|
-
|
23
|
-
def notification?
|
24
|
-
need_counter_caches?
|
25
|
-
end
|
26
|
-
|
27
|
-
def notification_response
|
28
|
-
response = []
|
29
|
-
if need_counter_caches?
|
30
|
-
response << counter_cache_messages.join("\n")
|
31
|
-
end
|
32
|
-
response
|
33
|
-
end
|
34
|
-
|
35
|
-
def console_title
|
36
|
-
title = ["Need Counter Cache"]
|
37
|
-
end
|
38
|
-
|
39
|
-
def log_messages(path = nil)
|
40
|
-
[counter_cache_messages(path)]
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_counter_cache(object, associations)
|
44
|
-
klazz = object.class
|
45
|
-
if (!possible_objects[klazz].nil? and possible_objects[klazz].include?(object)) and
|
46
|
-
(impossible_objects[klazz].nil? or !impossible_objects[klazz].include?(object))
|
47
|
-
klazz_associations[klazz] ||= []
|
48
|
-
klazz_associations[klazz] << associations
|
49
|
-
unique(klazz_associations[klazz])
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def add_possible_objects(objects)
|
54
|
-
klazz = objects.first.class
|
55
|
-
possible_objects[klazz] ||= []
|
56
|
-
possible_objects[klazz] << objects
|
57
|
-
unique(possible_objects[klazz])
|
58
|
-
end
|
59
|
-
|
60
|
-
def add_impossible_object(object)
|
61
|
-
klazz = object.class
|
62
|
-
impossible_objects[klazz] ||= []
|
63
|
-
impossible_objects[klazz] << object
|
64
|
-
impossible_objects[klazz].uniq!
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
def counter_cache_messages(path = nil)
|
69
|
-
messages = []
|
70
|
-
klazz_associations.each do |klazz, associations|
|
71
|
-
messages << [
|
72
|
-
"Need Counter Cache",
|
73
|
-
" #{klazz} => [#{associations.map(&:inspect).join(', ')}]"
|
74
|
-
]
|
75
|
-
end
|
76
|
-
messages
|
77
|
-
end
|
78
|
-
|
79
|
-
def unique(array)
|
80
|
-
array.flatten!
|
81
|
-
array.uniq!
|
82
|
-
end
|
83
|
-
|
84
|
-
def call_stack_messages
|
85
|
-
[]
|
86
|
-
end
|
87
|
-
|
88
|
-
def klazz_associations
|
89
|
-
@@klazz_associations ||= {}
|
90
|
-
end
|
91
|
-
|
92
|
-
def possible_objects
|
93
|
-
@@possible_objects ||= {}
|
94
|
-
end
|
95
|
-
|
96
|
-
def impossible_objects
|
97
|
-
@@impossible_objects ||= {}
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
data/lib/bullet/logger.rb
DELETED
data/lib/bulletware.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
class Bulletware
|
2
|
-
def initialize(app)
|
3
|
-
@app = app
|
4
|
-
end
|
5
|
-
|
6
|
-
def call(env)
|
7
|
-
return @app.call(env) unless Bullet.enable?
|
8
|
-
|
9
|
-
Bullet.start_request
|
10
|
-
status, headers, response = @app.call(env)
|
11
|
-
return [status, headers, response] if empty?(response)
|
12
|
-
|
13
|
-
if Bullet.notification?
|
14
|
-
if status == 200 and !response.body.frozen? and check_html?(headers, response)
|
15
|
-
response_body = response.body << Bullet.javascript_notification
|
16
|
-
headers['Content-Length'] = response_body.length.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
Bullet.growl_notification
|
20
|
-
Bullet.log_notification(env['PATH_INFO'])
|
21
|
-
end
|
22
|
-
response_body ||= response.body
|
23
|
-
Bullet.end_request
|
24
|
-
no_browser_cache(headers) if Bullet.disable_browser_cache
|
25
|
-
[status, headers, [response_body]]
|
26
|
-
end
|
27
|
-
|
28
|
-
# fix issue if response's body is a Proc
|
29
|
-
def empty?(response)
|
30
|
-
(response.is_a?(Array) && response.empty?) || !response.body.is_a?(String) || response.body.empty?
|
31
|
-
end
|
32
|
-
|
33
|
-
def check_html?(headers, response)
|
34
|
-
headers['Content-Type'] and headers['Content-Type'].include? 'text/html' and response.body =~ %r{<html.*</html>}m
|
35
|
-
end
|
36
|
-
|
37
|
-
def no_browser_cache(headers)
|
38
|
-
headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
39
|
-
headers["Pragma"] = "no-cache"
|
40
|
-
headers["Expires"] = "Wed, 09 Sep 2009 09:09:09 GMT"
|
41
|
-
end
|
42
|
-
end
|
data/spec/spec.opts
DELETED