bullet 2.0.0.beta.3 → 2.0.0
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.
- data/MIT-LICENSE +1 -1
- data/README.textile +2 -3
- data/README_for_rails2.textile +2 -3
- data/lib/bullet/notification/base.rb +7 -9
- data/lib/bullet/rack.rb +5 -3
- data/lib/bullet/version.rb +5 -0
- data/lib/bullet.rb +27 -38
- metadata +46 -51
- data/.rspec +0 -1
- data/Hacking.textile +0 -100
- data/Rakefile +0 -51
- data/VERSION +0 -1
- data/autotest/discover.rb +0 -1
- data/bullet.gemspec +0 -90
- data/lib/bullet/presenter/base.rb +0 -9
- data/lib/bullet/presenter/bullet_logger.rb +0 -28
- data/lib/bullet/presenter/growl.rb +0 -40
- data/lib/bullet/presenter/javascript_alert.rb +0 -15
- data/lib/bullet/presenter/javascript_console.rb +0 -28
- data/lib/bullet/presenter/javascript_helpers.rb +0 -13
- data/lib/bullet/presenter/rails_logger.rb +0 -15
- data/lib/bullet/presenter/xmpp.rb +0 -56
- data/lib/bullet/presenter.rb +0 -13
- data/rails/init.rb +0 -1
- data/spec/bullet/association_for_chris_spec.rb +0 -96
- data/spec/bullet/association_for_peschkaj_spec.rb +0 -86
- data/spec/bullet/association_spec.rb +0 -899
- data/spec/bullet/counter_spec.rb +0 -136
- data/spec/spec_helper.rb +0 -79
- data/tasks/bullet_tasks.rake +0 -9
data/MIT-LICENSE
CHANGED
data/README.textile
CHANGED
|
@@ -164,8 +164,7 @@ end
|
|
|
164
164
|
|
|
165
165
|
after(:each)
|
|
166
166
|
if Bullet.enable?
|
|
167
|
-
Bullet.
|
|
168
|
-
Bullet.log_notification('Test: ')
|
|
167
|
+
Bullet.perform_out_of_channel_notifications
|
|
169
168
|
Bullet.end_request
|
|
170
169
|
end
|
|
171
170
|
end
|
|
@@ -412,4 +411,4 @@ In the meanwhile, there's a log appended into <code>log/bullet.log</code> file.
|
|
|
412
411
|
****************************************************************************
|
|
413
412
|
|
|
414
413
|
|
|
415
|
-
Copyright (c) 2009 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
|
414
|
+
Copyright (c) 2009 - 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
data/README_for_rails2.textile
CHANGED
|
@@ -184,8 +184,7 @@ end
|
|
|
184
184
|
|
|
185
185
|
after(:each)
|
|
186
186
|
if Bullet.enable?
|
|
187
|
-
Bullet.
|
|
188
|
-
Bullet.log_notification('Test: ')
|
|
187
|
+
Bullet.perform_out_of_channel_notifications
|
|
189
188
|
Bullet.end_request
|
|
190
189
|
end
|
|
191
190
|
end
|
|
@@ -418,4 +417,4 @@ In the meanwhile, there's a log appended into <code>log/bullet.log</code> file.
|
|
|
418
417
|
****************************************************************************
|
|
419
418
|
|
|
420
419
|
|
|
421
|
-
Copyright (c) 2009 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
|
420
|
+
Copyright (c) 2009 - 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Bullet
|
|
2
2
|
module Notification
|
|
3
3
|
class Base
|
|
4
|
-
attr_accessor :
|
|
4
|
+
attr_accessor :notifier
|
|
5
5
|
attr_reader :base_class, :associations, :path
|
|
6
6
|
|
|
7
7
|
def initialize( base_class, associations, path = nil )
|
|
@@ -15,11 +15,11 @@ module Bullet
|
|
|
15
15
|
|
|
16
16
|
def body
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def body_with_caller
|
|
20
20
|
body
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
def standard_notice
|
|
24
24
|
@standard_notifice ||= title + "\n" + body
|
|
25
25
|
end
|
|
@@ -28,14 +28,12 @@ module Bullet
|
|
|
28
28
|
@full_notice ||= title + "\n" + body_with_caller
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def
|
|
32
|
-
|
|
33
|
-
self.presenter.send( :inline, self )
|
|
31
|
+
def notify_inline
|
|
32
|
+
self.notifier.inline_notify( self.full_notice )
|
|
34
33
|
end
|
|
35
34
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
self.presenter.send( :out_of_channel, self )
|
|
35
|
+
def notify_out_of_channel
|
|
36
|
+
self.notifier.out_of_channel_notify( self.full_notice )
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
def eql?( other )
|
data/lib/bullet/rack.rb
CHANGED
|
@@ -26,9 +26,11 @@ module Bullet
|
|
|
26
26
|
|
|
27
27
|
# fix issue if response's body is a Proc
|
|
28
28
|
def empty?(response)
|
|
29
|
-
|
|
29
|
+
# response may be ["Not Found"], ["Move Permanently"], etc.
|
|
30
|
+
(response.is_a?(Array) && response.size <= 1) ||
|
|
31
|
+
!response.body.is_a?(String) || response.body.empty?
|
|
30
32
|
end
|
|
31
|
-
|
|
33
|
+
|
|
32
34
|
def check_html?(headers, response)
|
|
33
35
|
headers['Content-Type'] and headers['Content-Type'].include? 'text/html' and response.body =~ %r{<html.*</html>}m
|
|
34
36
|
end
|
|
@@ -39,4 +41,4 @@ module Bullet
|
|
|
39
41
|
headers["Expires"] = "Wed, 09 Sep 2009 09:09:09 GMT"
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
|
-
end
|
|
44
|
+
end
|
data/lib/bullet.rb
CHANGED
|
@@ -12,11 +12,10 @@ module Bullet
|
|
|
12
12
|
autoload :Rack, 'bullet/rack'
|
|
13
13
|
autoload :BulletLogger, 'bullet/logger'
|
|
14
14
|
autoload :Notification, 'bullet/notification'
|
|
15
|
-
autoload :Presenter, 'bullet/presenter'
|
|
16
15
|
autoload :Detector, 'bullet/detector'
|
|
17
16
|
autoload :Registry, 'bullet/registry'
|
|
18
17
|
autoload :NotificationCollector, 'bullet/notification_collector'
|
|
19
|
-
|
|
18
|
+
|
|
20
19
|
if defined? Rails::Railtie
|
|
21
20
|
# compatible with rails 3.0.0.beta4
|
|
22
21
|
class BulletRailtie < Rails::Railtie
|
|
@@ -27,23 +26,18 @@ module Bullet
|
|
|
27
26
|
end
|
|
28
27
|
|
|
29
28
|
class <<self
|
|
30
|
-
attr_accessor :enable, :
|
|
29
|
+
attr_accessor :enable, :disable_browser_cache
|
|
31
30
|
attr_reader :notification_collector
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
|
|
32
|
+
delegate :alert=, :console=, :growl=, :rails_logger=, :xmpp=, :to => UniformNotifier
|
|
33
|
+
|
|
34
|
+
DETECTORS = [ Bullet::Detector::NPlusOneQuery,
|
|
34
35
|
Bullet::Detector::UnusedEagerAssociation,
|
|
35
36
|
Bullet::Detector::Counter ]
|
|
36
37
|
|
|
37
|
-
PRESENTERS = [ Bullet::Presenter::JavascriptAlert,
|
|
38
|
-
Bullet::Presenter::JavascriptConsole,
|
|
39
|
-
Bullet::Presenter::Growl,
|
|
40
|
-
Bullet::Presenter::Xmpp,
|
|
41
|
-
Bullet::Presenter::RailsLogger,
|
|
42
|
-
Bullet::Presenter::BulletLogger ]
|
|
43
|
-
|
|
44
38
|
def enable=(enable)
|
|
45
39
|
@enable = enable
|
|
46
|
-
if enable?
|
|
40
|
+
if enable?
|
|
47
41
|
Bullet::ActiveRecord.enable
|
|
48
42
|
if Rails.version =~ /^2./
|
|
49
43
|
Bullet::ActionController.enable
|
|
@@ -55,64 +49,59 @@ module Bullet
|
|
|
55
49
|
@enable == true
|
|
56
50
|
end
|
|
57
51
|
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def bullet_logger=(bullet_logger)
|
|
67
|
-
Bullet::Presenter::BulletLogger.setup if bullet_logger
|
|
52
|
+
def bullet_logger=(active)
|
|
53
|
+
if active
|
|
54
|
+
bullet_log_file = File.open( 'log/bullet.log', 'a+' )
|
|
55
|
+
bullet_log_file.sync
|
|
56
|
+
UniformNotifier.customized_logger = bullet_log_file
|
|
57
|
+
end
|
|
68
58
|
end
|
|
69
59
|
|
|
70
60
|
def start_request
|
|
71
|
-
|
|
72
|
-
@notification_collector.reset
|
|
61
|
+
notification_collector.reset
|
|
73
62
|
DETECTORS.each {|bullet| bullet.start_request}
|
|
74
63
|
end
|
|
75
64
|
|
|
76
65
|
def end_request
|
|
77
66
|
DETECTORS.each {|bullet| bullet.end_request}
|
|
78
67
|
end
|
|
79
|
-
|
|
68
|
+
|
|
80
69
|
def clear
|
|
81
70
|
DETECTORS.each {|bullet| bullet.clear}
|
|
82
71
|
end
|
|
83
72
|
|
|
84
|
-
def
|
|
85
|
-
|
|
73
|
+
def notification_collector
|
|
74
|
+
@notification_collector ||= Bullet::NotificationCollector.new
|
|
86
75
|
end
|
|
87
76
|
|
|
88
77
|
def notification?
|
|
89
78
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
90
|
-
|
|
79
|
+
notification_collector.notifications_present?
|
|
91
80
|
end
|
|
92
81
|
|
|
93
82
|
def gather_inline_notifications
|
|
94
83
|
responses = []
|
|
95
|
-
|
|
96
|
-
responses << notification.
|
|
84
|
+
for_each_active_notifier_with_notification do |notification|
|
|
85
|
+
responses << notification.notify_inline
|
|
97
86
|
end
|
|
98
87
|
responses.join( "\n" )
|
|
99
88
|
end
|
|
100
89
|
|
|
101
90
|
def perform_out_of_channel_notifications
|
|
102
|
-
|
|
103
|
-
notification.
|
|
91
|
+
for_each_active_notifier_with_notification do |notification|
|
|
92
|
+
notification.notify_out_of_channel
|
|
104
93
|
end
|
|
105
94
|
end
|
|
106
95
|
|
|
107
96
|
private
|
|
108
|
-
def
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
notification.
|
|
97
|
+
def for_each_active_notifier_with_notification
|
|
98
|
+
UniformNotifier.active_notifiers.each do |notifier|
|
|
99
|
+
notification_collector.collection.each do |notification|
|
|
100
|
+
notification.notifier = notifier
|
|
112
101
|
yield notification
|
|
113
102
|
end
|
|
114
103
|
end
|
|
115
104
|
end
|
|
116
105
|
end
|
|
117
106
|
|
|
118
|
-
end
|
|
107
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bullet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 15
|
|
5
|
+
prerelease: false
|
|
5
6
|
segments:
|
|
6
7
|
- 2
|
|
7
8
|
- 0
|
|
8
9
|
- 0
|
|
9
|
-
|
|
10
|
-
- 3
|
|
11
|
-
version: 2.0.0.beta.3
|
|
10
|
+
version: 2.0.0
|
|
12
11
|
platform: ruby
|
|
13
12
|
authors:
|
|
14
13
|
- Richard Huang
|
|
@@ -16,101 +15,97 @@ autorequire:
|
|
|
16
15
|
bindir: bin
|
|
17
16
|
cert_chain: []
|
|
18
17
|
|
|
19
|
-
date: 2010-
|
|
18
|
+
date: 2010-11-19 00:00:00 +08:00
|
|
20
19
|
default_executable:
|
|
21
|
-
dependencies:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
|
23
|
+
none: false
|
|
24
|
+
requirements:
|
|
25
|
+
- - ~>
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
hash: 23
|
|
28
|
+
segments:
|
|
29
|
+
- 1
|
|
30
|
+
- 0
|
|
31
|
+
- 0
|
|
32
|
+
version: 1.0.0
|
|
33
|
+
requirement: *id001
|
|
34
|
+
name: uniform_notifier
|
|
35
|
+
prerelease: false
|
|
36
|
+
type: :runtime
|
|
37
|
+
description: A rails plugin to kill N+1 queries and unused eager loading.
|
|
38
|
+
email:
|
|
39
|
+
- flyerhzm@gmail.com
|
|
25
40
|
executables: []
|
|
26
41
|
|
|
27
42
|
extensions: []
|
|
28
43
|
|
|
29
44
|
extra_rdoc_files:
|
|
30
|
-
- README.textile
|
|
31
|
-
- README_for_rails2.textile
|
|
32
|
-
files:
|
|
33
|
-
- .rspec
|
|
34
|
-
- Hacking.textile
|
|
35
45
|
- MIT-LICENSE
|
|
36
46
|
- README.textile
|
|
37
47
|
- README_for_rails2.textile
|
|
38
|
-
|
|
39
|
-
- VERSION
|
|
40
|
-
- autotest/discover.rb
|
|
41
|
-
- bullet.gemspec
|
|
42
|
-
- lib/bullet.rb
|
|
48
|
+
files:
|
|
43
49
|
- lib/bullet/action_controller2.rb
|
|
44
50
|
- lib/bullet/active_record2.rb
|
|
45
51
|
- lib/bullet/active_record3.rb
|
|
46
|
-
- lib/bullet/detector.rb
|
|
47
52
|
- lib/bullet/detector/association.rb
|
|
48
53
|
- lib/bullet/detector/base.rb
|
|
49
54
|
- lib/bullet/detector/counter.rb
|
|
50
55
|
- lib/bullet/detector/n_plus_one_query.rb
|
|
51
56
|
- lib/bullet/detector/unused_eager_association.rb
|
|
52
|
-
- lib/bullet/
|
|
57
|
+
- lib/bullet/detector.rb
|
|
53
58
|
- lib/bullet/notification/base.rb
|
|
54
59
|
- lib/bullet/notification/counter_cache.rb
|
|
55
60
|
- lib/bullet/notification/n_plus_one_query.rb
|
|
56
61
|
- lib/bullet/notification/unused_eager_loading.rb
|
|
62
|
+
- lib/bullet/notification.rb
|
|
57
63
|
- lib/bullet/notification_collector.rb
|
|
58
|
-
- lib/bullet/presenter.rb
|
|
59
|
-
- lib/bullet/presenter/base.rb
|
|
60
|
-
- lib/bullet/presenter/bullet_logger.rb
|
|
61
|
-
- lib/bullet/presenter/growl.rb
|
|
62
|
-
- lib/bullet/presenter/javascript_alert.rb
|
|
63
|
-
- lib/bullet/presenter/javascript_console.rb
|
|
64
|
-
- lib/bullet/presenter/javascript_helpers.rb
|
|
65
|
-
- lib/bullet/presenter/rails_logger.rb
|
|
66
|
-
- lib/bullet/presenter/xmpp.rb
|
|
67
64
|
- lib/bullet/rack.rb
|
|
68
|
-
- lib/bullet/registry.rb
|
|
69
65
|
- lib/bullet/registry/association.rb
|
|
70
66
|
- lib/bullet/registry/base.rb
|
|
71
67
|
- lib/bullet/registry/object.rb
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
78
|
-
- tasks/bullet_tasks.rake
|
|
68
|
+
- lib/bullet/registry.rb
|
|
69
|
+
- lib/bullet/version.rb
|
|
70
|
+
- lib/bullet.rb
|
|
71
|
+
- MIT-LICENSE
|
|
72
|
+
- README.textile
|
|
73
|
+
- README_for_rails2.textile
|
|
79
74
|
has_rdoc: true
|
|
80
75
|
homepage: http://github.com/flyerhzm/bullet
|
|
81
76
|
licenses: []
|
|
82
77
|
|
|
83
78
|
post_install_message:
|
|
84
|
-
rdoc_options:
|
|
85
|
-
|
|
79
|
+
rdoc_options: []
|
|
80
|
+
|
|
86
81
|
require_paths:
|
|
87
82
|
- lib
|
|
88
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
none: false
|
|
89
85
|
requirements:
|
|
90
86
|
- - ">="
|
|
91
87
|
- !ruby/object:Gem::Version
|
|
88
|
+
hash: 3
|
|
92
89
|
segments:
|
|
93
90
|
- 0
|
|
94
91
|
version: "0"
|
|
95
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
|
+
none: false
|
|
96
94
|
requirements:
|
|
97
|
-
- - "
|
|
95
|
+
- - ">="
|
|
98
96
|
- !ruby/object:Gem::Version
|
|
97
|
+
hash: 23
|
|
99
98
|
segments:
|
|
100
99
|
- 1
|
|
101
100
|
- 3
|
|
102
|
-
-
|
|
103
|
-
version: 1.3.
|
|
101
|
+
- 6
|
|
102
|
+
version: 1.3.6
|
|
104
103
|
requirements: []
|
|
105
104
|
|
|
106
105
|
rubyforge_project:
|
|
107
|
-
rubygems_version: 1.3.
|
|
106
|
+
rubygems_version: 1.3.7
|
|
108
107
|
signing_key:
|
|
109
108
|
specification_version: 3
|
|
110
|
-
summary: A rails plugin to kill N+1 queries and unused eager loading
|
|
111
|
-
test_files:
|
|
112
|
-
|
|
113
|
-
- spec/bullet/counter_spec.rb
|
|
114
|
-
- spec/bullet/association_spec.rb
|
|
115
|
-
- spec/bullet/association_for_chris_spec.rb
|
|
116
|
-
- spec/bullet/association_for_peschkaj_spec.rb
|
|
109
|
+
summary: A rails plugin to kill N+1 queries and unused eager loading.
|
|
110
|
+
test_files: []
|
|
111
|
+
|
data/.rspec
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--colour --format d
|
data/Hacking.textile
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
h1. Bullet Overview for Developers
|
|
2
|
-
This file aims to give developers a quick tour of the bullet internals, making
|
|
3
|
-
it (hopefully) easier to extend or enhance the Bullet gem.
|
|
4
|
-
|
|
5
|
-
h2. General Control Flow aka. 10000 Meter View
|
|
6
|
-
When Rails is initialized, Bullet will extend ActiveRecord (and if you're using
|
|
7
|
-
Rails 2.x ActiveController too) with the relevant modules and methods found
|
|
8
|
-
in lib/bullet/active_recordX.rb and lib/bullet/action_controller2.rb. If you're
|
|
9
|
-
running Rails 3, Bullet will integrate itself as a middleware into the Rack
|
|
10
|
-
stack, so ActionController does not need to be extended.
|
|
11
|
-
|
|
12
|
-
The ActiveRecord extensions will call methods in a given detector class, when
|
|
13
|
-
certain methods are called.
|
|
14
|
-
|
|
15
|
-
Detector classes contain all the logic to recognize
|
|
16
|
-
a noteworthy event. If such an event is detected, an instance of the
|
|
17
|
-
corresponding Notification class is created and stored in a Set instance in the
|
|
18
|
-
main Bullet module (the 'notification collector').
|
|
19
|
-
|
|
20
|
-
Notification instances contain the message that will be displayed, and will
|
|
21
|
-
use a Presenter class to display their message to the user.
|
|
22
|
-
|
|
23
|
-
Each Presenter knows how to present the message either "inline" (as in: the
|
|
24
|
-
message text will be inlined into the request response, such as javascript
|
|
25
|
-
alerts) or "out-of-channel" (completely independent of the request response,
|
|
26
|
-
such as growl or xmpp).
|
|
27
|
-
|
|
28
|
-
So the flow of a request goes like this:
|
|
29
|
-
1. Bullet.start_request is called, which resets all the detectors and empties
|
|
30
|
-
the notification collector
|
|
31
|
-
2. The request is handled by Rails, and the installed ActiveRecord extensions
|
|
32
|
-
trigger Detector callbacks
|
|
33
|
-
3. Detectors once called, will determine whether something noteworthy happend.
|
|
34
|
-
If yes, then a Notification is created and stored in the notification collector.
|
|
35
|
-
4. Rails finishes handling the request
|
|
36
|
-
5. For each notification in the collector, Bullet will iterate over each
|
|
37
|
-
Presenter and will try to generate an inline message that will be appended to
|
|
38
|
-
the generated reponse body.
|
|
39
|
-
6. The response is returned to the client.
|
|
40
|
-
7. Bullet will try to generate an out-of-channel message for each notification.
|
|
41
|
-
8. Bullet calls end_request for each detector.
|
|
42
|
-
9. Goto 1.
|
|
43
|
-
|
|
44
|
-
h2. Adding Presenters
|
|
45
|
-
To add a presenter, you will need to:
|
|
46
|
-
* Add the class to the PRESENTERS constant in the main Bullet module
|
|
47
|
-
* Add an autoload directive to lib/bullet/presenter.rb
|
|
48
|
-
* Create your presenter class in the Bullet::Presenter namespace
|
|
49
|
-
|
|
50
|
-
Presenter classes will need the following class methods:
|
|
51
|
-
* .active? which returns a boolean to indicate if the presenter is active (so
|
|
52
|
-
* that presenters the user doesn't want can be skipped).
|
|
53
|
-
|
|
54
|
-
and at least one of:
|
|
55
|
-
* .out_of_channel( notification ) which will display the notification to the
|
|
56
|
-
user outside of the request response
|
|
57
|
-
or
|
|
58
|
-
* .inline( notification ) which will generate the notification presentation fit
|
|
59
|
-
to be appended to the generated HTML request response (if you want to inject
|
|
60
|
-
content on the result page, such as a javascript alert).
|
|
61
|
-
|
|
62
|
-
Have a look at lib/bullet/javascript_alert.rb as a trivial example for an
|
|
63
|
-
inline presenter and lib/bullet/rails_logger.rb to see how a minimal
|
|
64
|
-
out-of-channel presenter looks like.
|
|
65
|
-
|
|
66
|
-
h2. Adding Notification Types
|
|
67
|
-
If you want to add more kinds of things that Bullet can detect, a little more
|
|
68
|
-
work is needed than if you were just adding a Presenter, but the concepts are
|
|
69
|
-
similar.
|
|
70
|
-
|
|
71
|
-
* Add the class to the DETECTORS constant in the main Bullet module
|
|
72
|
-
* Add (if needed) Rails monkey patches to Bullet.enable
|
|
73
|
-
* Create your presenter class in the Bullet::Detector namespace
|
|
74
|
-
* Add an autoload directive to lib/bullet/detector.rb
|
|
75
|
-
* Create a corresponding notification class in the Bullet::Notification namespace
|
|
76
|
-
* Add an autoload directive to lib/bullet/notification.rb
|
|
77
|
-
|
|
78
|
-
As a rule of thumb, you can assume that each Detector will have its own
|
|
79
|
-
Notification class. If you follow the principle of Separation of Concerns I
|
|
80
|
-
can't really think of an example where one would deviate from this rule.
|
|
81
|
-
|
|
82
|
-
Since the detection of pathological associations is a bit hairy, I'd recommend
|
|
83
|
-
having a look at the counter cache detector and associated notification to get
|
|
84
|
-
a feel for what is needed to get off the ground.
|
|
85
|
-
|
|
86
|
-
h3. Detectors
|
|
87
|
-
The only things you'll need to consider when building your Detector class is
|
|
88
|
-
that it will need to supply the .start_request, .end_request and .clear class
|
|
89
|
-
methods.
|
|
90
|
-
|
|
91
|
-
Simple implementations are provided by Bullet::Detector::Base for start_request
|
|
92
|
-
and end_request, you will have to supply your own clear method.
|
|
93
|
-
|
|
94
|
-
h3. Notifications
|
|
95
|
-
For notifications you will want to supply a #title and #body instance method,
|
|
96
|
-
and check to see if the #initialize and #full_notice methods in the
|
|
97
|
-
Bullet::Notification::Base class fit your needs.
|
|
98
|
-
|
|
99
|
-
The interaction with the presenters encapsulated in the Base class, so you
|
|
100
|
-
won't have to worry about that.
|
data/Rakefile
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'rake'
|
|
2
|
-
require 'rspec/core/rake_task'
|
|
3
|
-
require 'rake/rdoctask'
|
|
4
|
-
require 'jeweler'
|
|
5
|
-
|
|
6
|
-
desc 'Default: run unit tests.'
|
|
7
|
-
task :default => :spec
|
|
8
|
-
|
|
9
|
-
desc 'Generate documentation for the bullet plugin.'
|
|
10
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
11
|
-
rdoc.rdoc_dir = 'rdoc'
|
|
12
|
-
rdoc.title = 'Bullet'
|
|
13
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
|
14
|
-
rdoc.rdoc_files.include('README')
|
|
15
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
19
|
-
|
|
20
|
-
desc "Run all examples using rcov"
|
|
21
|
-
RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
|
|
22
|
-
t.rcov = true
|
|
23
|
-
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,spec/spec_helper.rb"]
|
|
24
|
-
t.rcov_opts << %[--no-html --aggregate coverage.data]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
task :cleanup_rcov_files do
|
|
28
|
-
rm_rf 'coverage.data'
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
task :clobber do
|
|
32
|
-
rm_rf 'pkg'
|
|
33
|
-
rm_rf 'tmp'
|
|
34
|
-
rm_rf 'coverage'
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
begin
|
|
38
|
-
Jeweler::Tasks.new do |gemspec|
|
|
39
|
-
gemspec.name = "bullet"
|
|
40
|
-
gemspec.summary = "A rails plugin to kill N+1 queries and unused eager loading"
|
|
41
|
-
gemspec.description = "The Bullet plugin is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries) or when you're using eager loading that isn't necessary."
|
|
42
|
-
gemspec.email = "flyerhzm@gmail.com"
|
|
43
|
-
gemspec.homepage = "http://github.com/flyerhzm/bullet"
|
|
44
|
-
gemspec.authors = ["Richard Huang"]
|
|
45
|
-
gemspec.files.exclude '.gitignore'
|
|
46
|
-
gemspec.files.exclude 'log/*'
|
|
47
|
-
end
|
|
48
|
-
Jeweler::GemcutterTasks.new
|
|
49
|
-
rescue LoadError
|
|
50
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
51
|
-
end
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.0.0.beta.3
|
data/autotest/discover.rb
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Autotest.add_discovery { "rspec2" }
|
data/bullet.gemspec
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
-
# -*- encoding: utf-8 -*-
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |s|
|
|
7
|
-
s.name = %q{bullet}
|
|
8
|
-
s.version = "2.0.0.beta.3"
|
|
9
|
-
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.authors = ["Richard Huang"]
|
|
12
|
-
s.date = %q{2010-07-14}
|
|
13
|
-
s.description = %q{The Bullet plugin is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries) or when you're using eager loading that isn't necessary.}
|
|
14
|
-
s.email = %q{flyerhzm@gmail.com}
|
|
15
|
-
s.extra_rdoc_files = [
|
|
16
|
-
"README.textile",
|
|
17
|
-
"README_for_rails2.textile"
|
|
18
|
-
]
|
|
19
|
-
s.files = [
|
|
20
|
-
".rspec",
|
|
21
|
-
"Hacking.textile",
|
|
22
|
-
"MIT-LICENSE",
|
|
23
|
-
"README.textile",
|
|
24
|
-
"README_for_rails2.textile",
|
|
25
|
-
"Rakefile",
|
|
26
|
-
"VERSION",
|
|
27
|
-
"autotest/discover.rb",
|
|
28
|
-
"bullet.gemspec",
|
|
29
|
-
"lib/bullet.rb",
|
|
30
|
-
"lib/bullet/action_controller2.rb",
|
|
31
|
-
"lib/bullet/active_record2.rb",
|
|
32
|
-
"lib/bullet/active_record3.rb",
|
|
33
|
-
"lib/bullet/detector.rb",
|
|
34
|
-
"lib/bullet/detector/association.rb",
|
|
35
|
-
"lib/bullet/detector/base.rb",
|
|
36
|
-
"lib/bullet/detector/counter.rb",
|
|
37
|
-
"lib/bullet/detector/n_plus_one_query.rb",
|
|
38
|
-
"lib/bullet/detector/unused_eager_association.rb",
|
|
39
|
-
"lib/bullet/notification.rb",
|
|
40
|
-
"lib/bullet/notification/base.rb",
|
|
41
|
-
"lib/bullet/notification/counter_cache.rb",
|
|
42
|
-
"lib/bullet/notification/n_plus_one_query.rb",
|
|
43
|
-
"lib/bullet/notification/unused_eager_loading.rb",
|
|
44
|
-
"lib/bullet/notification_collector.rb",
|
|
45
|
-
"lib/bullet/presenter.rb",
|
|
46
|
-
"lib/bullet/presenter/base.rb",
|
|
47
|
-
"lib/bullet/presenter/bullet_logger.rb",
|
|
48
|
-
"lib/bullet/presenter/growl.rb",
|
|
49
|
-
"lib/bullet/presenter/javascript_alert.rb",
|
|
50
|
-
"lib/bullet/presenter/javascript_console.rb",
|
|
51
|
-
"lib/bullet/presenter/javascript_helpers.rb",
|
|
52
|
-
"lib/bullet/presenter/rails_logger.rb",
|
|
53
|
-
"lib/bullet/presenter/xmpp.rb",
|
|
54
|
-
"lib/bullet/rack.rb",
|
|
55
|
-
"lib/bullet/registry.rb",
|
|
56
|
-
"lib/bullet/registry/association.rb",
|
|
57
|
-
"lib/bullet/registry/base.rb",
|
|
58
|
-
"lib/bullet/registry/object.rb",
|
|
59
|
-
"rails/init.rb",
|
|
60
|
-
"spec/bullet/association_for_chris_spec.rb",
|
|
61
|
-
"spec/bullet/association_for_peschkaj_spec.rb",
|
|
62
|
-
"spec/bullet/association_spec.rb",
|
|
63
|
-
"spec/bullet/counter_spec.rb",
|
|
64
|
-
"spec/spec_helper.rb",
|
|
65
|
-
"tasks/bullet_tasks.rake"
|
|
66
|
-
]
|
|
67
|
-
s.homepage = %q{http://github.com/flyerhzm/bullet}
|
|
68
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
|
69
|
-
s.require_paths = ["lib"]
|
|
70
|
-
s.rubygems_version = %q{1.3.6}
|
|
71
|
-
s.summary = %q{A rails plugin to kill N+1 queries and unused eager loading}
|
|
72
|
-
s.test_files = [
|
|
73
|
-
"spec/spec_helper.rb",
|
|
74
|
-
"spec/bullet/counter_spec.rb",
|
|
75
|
-
"spec/bullet/association_spec.rb",
|
|
76
|
-
"spec/bullet/association_for_chris_spec.rb",
|
|
77
|
-
"spec/bullet/association_for_peschkaj_spec.rb"
|
|
78
|
-
]
|
|
79
|
-
|
|
80
|
-
if s.respond_to? :specification_version then
|
|
81
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
82
|
-
s.specification_version = 3
|
|
83
|
-
|
|
84
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
85
|
-
else
|
|
86
|
-
end
|
|
87
|
-
else
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|