bullet 2.0.0.rc1 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Richard Huang (flyerhzm@gmail.com)
1
+ Copyright (c) 2009 - 2010 Richard Huang (flyerhzm@gmail.com)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -412,4 +412,4 @@ In the meanwhile, there's a log appended into <code>log/bullet.log</code> file.
412
412
  ****************************************************************************
413
413
 
414
414
 
415
- Copyright (c) 2009 Richard Huang (flyerhzm@gmail.com), released under the MIT license
415
+ Copyright (c) 2009 - 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -418,4 +418,4 @@ In the meanwhile, there's a log appended into <code>log/bullet.log</code> file.
418
418
  ****************************************************************************
419
419
 
420
420
 
421
- Copyright (c) 2009 Richard Huang (flyerhzm@gmail.com), released under the MIT license
421
+ Copyright (c) 2009 - 2010 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -68,8 +68,7 @@ module Bullet
68
68
  end
69
69
 
70
70
  def start_request
71
- @notification_collector ||= Bullet::NotificationCollector.new
72
- @notification_collector.reset
71
+ notification_collector.reset
73
72
  DETECTORS.each {|bullet| bullet.start_request}
74
73
  end
75
74
 
@@ -85,9 +84,13 @@ module Bullet
85
84
  PRESENTERS.select { |presenter| presenter.send :active? }
86
85
  end
87
86
 
87
+ def notification_collector
88
+ @notification_collector ||= Bullet::NotificationCollector.new
89
+ end
90
+
88
91
  def notification?
89
92
  Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
90
- @notification_collector.notifications_present?
93
+ notification_collector.notifications_present?
91
94
  end
92
95
 
93
96
  def gather_inline_notifications
@@ -107,7 +110,7 @@ module Bullet
107
110
  private
108
111
  def for_each_active_presenter_with_notification
109
112
  active_presenters.each do |presenter|
110
- @notification_collector.collection.each do |notification|
113
+ notification_collector.collection.each do |notification|
111
114
  notification.presenter = presenter
112
115
  yield notification
113
116
  end
@@ -115,4 +118,4 @@ module Bullet
115
118
  end
116
119
  end
117
120
 
118
- end
121
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ module Bullet
3
+ VERSION = "2.0.0.rc2"
4
+ end
5
+
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 977940591
4
5
  prerelease: true
5
6
  segments:
6
7
  - 2
7
8
  - 0
8
9
  - 0
9
- - rc1
10
- version: 2.0.0.rc1
10
+ - rc2
11
+ version: 2.0.0.rc2
11
12
  platform: ruby
12
13
  authors:
13
14
  - Richard Huang
@@ -15,101 +16,91 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-08-10 00:00:00 +08:00
19
+ date: 2010-10-07 00:00:00 +08:00
19
20
  default_executable:
20
21
  dependencies: []
21
22
 
22
- 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.
23
- email: flyerhzm@gmail.com
23
+ description: A rails plugin to kill N+1 queries and unused eager loading.
24
+ email:
25
+ - flyerhzm@gmail.com
24
26
  executables: []
25
27
 
26
28
  extensions: []
27
29
 
28
30
  extra_rdoc_files:
29
- - README.textile
30
- - README_for_rails2.textile
31
- files:
32
- - .rspec
33
- - Hacking.textile
34
31
  - MIT-LICENSE
35
32
  - README.textile
36
33
  - README_for_rails2.textile
37
- - Rakefile
38
- - VERSION
39
- - autotest/discover.rb
40
- - bullet.gemspec
34
+ files:
41
35
  - lib/bullet.rb
42
- - lib/bullet/action_controller2.rb
43
- - lib/bullet/active_record2.rb
44
- - lib/bullet/active_record3.rb
45
- - lib/bullet/detector.rb
46
- - lib/bullet/detector/association.rb
47
- - lib/bullet/detector/base.rb
48
- - lib/bullet/detector/counter.rb
49
- - lib/bullet/detector/n_plus_one_query.rb
50
- - lib/bullet/detector/unused_eager_association.rb
51
- - lib/bullet/notification.rb
36
+ - lib/bullet/notification_collector.rb
52
37
  - lib/bullet/notification/base.rb
53
38
  - lib/bullet/notification/counter_cache.rb
54
39
  - lib/bullet/notification/n_plus_one_query.rb
55
40
  - lib/bullet/notification/unused_eager_loading.rb
56
- - lib/bullet/notification_collector.rb
57
- - lib/bullet/presenter.rb
41
+ - lib/bullet/version.rb
42
+ - lib/bullet/detector/base.rb
43
+ - lib/bullet/detector/unused_eager_association.rb
44
+ - lib/bullet/detector/counter.rb
45
+ - lib/bullet/detector/association.rb
46
+ - lib/bullet/detector/n_plus_one_query.rb
47
+ - lib/bullet/detector.rb
48
+ - lib/bullet/presenter/rails_logger.rb
58
49
  - lib/bullet/presenter/base.rb
59
- - lib/bullet/presenter/bullet_logger.rb
60
- - lib/bullet/presenter/growl.rb
61
50
  - lib/bullet/presenter/javascript_alert.rb
62
- - lib/bullet/presenter/javascript_console.rb
63
51
  - lib/bullet/presenter/javascript_helpers.rb
64
- - lib/bullet/presenter/rails_logger.rb
52
+ - lib/bullet/presenter/growl.rb
53
+ - lib/bullet/presenter/javascript_console.rb
54
+ - lib/bullet/presenter/bullet_logger.rb
65
55
  - lib/bullet/presenter/xmpp.rb
66
- - lib/bullet/rack.rb
67
56
  - lib/bullet/registry.rb
68
- - lib/bullet/registry/association.rb
57
+ - lib/bullet/notification.rb
58
+ - lib/bullet/active_record2.rb
59
+ - lib/bullet/rack.rb
69
60
  - lib/bullet/registry/base.rb
70
61
  - lib/bullet/registry/object.rb
71
- - rails/init.rb
72
- - spec/bullet/association_for_chris_spec.rb
73
- - spec/bullet/association_for_peschkaj_spec.rb
74
- - spec/bullet/association_spec.rb
75
- - spec/bullet/counter_spec.rb
76
- - spec/spec_helper.rb
77
- - tasks/bullet_tasks.rake
62
+ - lib/bullet/registry/association.rb
63
+ - lib/bullet/action_controller2.rb
64
+ - lib/bullet/active_record3.rb
65
+ - lib/bullet/presenter.rb
66
+ - MIT-LICENSE
67
+ - README.textile
68
+ - README_for_rails2.textile
78
69
  has_rdoc: true
79
70
  homepage: http://github.com/flyerhzm/bullet
80
71
  licenses: []
81
72
 
82
73
  post_install_message:
83
- rdoc_options:
84
- - --charset=UTF-8
74
+ rdoc_options: []
75
+
85
76
  require_paths:
86
77
  - lib
87
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
88
80
  requirements:
89
81
  - - ">="
90
82
  - !ruby/object:Gem::Version
83
+ hash: 3
91
84
  segments:
92
85
  - 0
93
86
  version: "0"
94
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
95
89
  requirements:
96
- - - ">"
90
+ - - ">="
97
91
  - !ruby/object:Gem::Version
92
+ hash: 23
98
93
  segments:
99
94
  - 1
100
95
  - 3
101
- - 1
102
- version: 1.3.1
96
+ - 6
97
+ version: 1.3.6
103
98
  requirements: []
104
99
 
105
100
  rubyforge_project:
106
- rubygems_version: 1.3.6
101
+ rubygems_version: 1.3.7
107
102
  signing_key:
108
103
  specification_version: 3
109
- summary: A rails plugin to kill N+1 queries and unused eager loading
110
- test_files:
111
- - spec/spec_helper.rb
112
- - spec/bullet/counter_spec.rb
113
- - spec/bullet/association_spec.rb
114
- - spec/bullet/association_for_chris_spec.rb
115
- - spec/bullet/association_for_peschkaj_spec.rb
104
+ summary: A rails plugin to kill N+1 queries and unused eager loading.
105
+ test_files: []
106
+
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --colour --format d
@@ -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.rc1
@@ -1 +0,0 @@
1
- Autotest.add_discovery { "rspec2" }
@@ -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.rc1"
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-08-10}
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
-