bullet 2.0.0.beta.2 → 2.0.0.beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/.rspec +1 -0
  2. data/Hacking.textile +100 -0
  3. data/README.textile +36 -5
  4. data/README_for_rails2.textile +17 -0
  5. data/Rakefile +33 -16
  6. data/VERSION +1 -1
  7. data/autotest/discover.rb +1 -0
  8. data/bullet.gemspec +32 -9
  9. data/lib/bullet.rb +69 -38
  10. data/lib/bullet/action_controller2.rb +4 -4
  11. data/lib/bullet/active_record2.rb +16 -16
  12. data/lib/bullet/active_record3.rb +16 -25
  13. data/lib/bullet/detector.rb +9 -0
  14. data/lib/bullet/detector/association.rb +135 -0
  15. data/lib/bullet/detector/base.rb +19 -0
  16. data/lib/bullet/detector/counter.rb +43 -0
  17. data/lib/bullet/detector/n_plus_one_query.rb +39 -0
  18. data/lib/bullet/detector/unused_eager_association.rb +39 -0
  19. data/lib/bullet/notification.rb +4 -79
  20. data/lib/bullet/notification/base.rb +59 -0
  21. data/lib/bullet/notification/counter_cache.rb +13 -0
  22. data/lib/bullet/notification/n_plus_one_query.rb +32 -0
  23. data/lib/bullet/notification/unused_eager_loading.rb +14 -0
  24. data/lib/bullet/notification_collector.rb +25 -0
  25. data/lib/bullet/presenter.rb +13 -0
  26. data/lib/bullet/presenter/base.rb +9 -0
  27. data/lib/bullet/presenter/bullet_logger.rb +28 -0
  28. data/lib/bullet/presenter/growl.rb +40 -0
  29. data/lib/bullet/presenter/javascript_alert.rb +15 -0
  30. data/lib/bullet/presenter/javascript_console.rb +28 -0
  31. data/lib/bullet/presenter/javascript_helpers.rb +13 -0
  32. data/lib/bullet/presenter/rails_logger.rb +15 -0
  33. data/lib/bullet/presenter/xmpp.rb +56 -0
  34. data/lib/bullet/rack.rb +42 -0
  35. data/lib/bullet/registry.rb +7 -0
  36. data/lib/bullet/registry/association.rb +16 -0
  37. data/lib/bullet/registry/base.rb +39 -0
  38. data/lib/bullet/registry/object.rb +15 -0
  39. data/spec/bullet/association_for_chris_spec.rb +6 -6
  40. data/spec/bullet/association_for_peschkaj_spec.rb +6 -6
  41. data/spec/bullet/association_spec.rb +118 -262
  42. data/spec/bullet/counter_spec.rb +10 -10
  43. data/spec/spec_helper.rb +51 -17
  44. metadata +32 -9
  45. data/lib/bullet/association.rb +0 -294
  46. data/lib/bullet/counter.rb +0 -101
  47. data/lib/bullet/logger.rb +0 -9
  48. data/lib/bulletware.rb +0 -42
  49. data/spec/spec.opts +0 -3
@@ -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
@@ -1,9 +0,0 @@
1
- module Bullet
2
- class BulletLogger < Logger
3
- LOG_FILE = File.join(Rails.root, 'log/bullet.log')
4
-
5
- def format_message(severity, timestamp, progname, msg)
6
- "#{timestamp.to_formatted_s(:db)}[#{severity}] #{msg}\n"
7
- end
8
- end
9
- end
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
@@ -1,3 +0,0 @@
1
- --colour
2
- --format
3
- specdoc