bullet 4.7.0 → 4.8.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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +17 -17
  4. data/CHANGELOG.md +15 -0
  5. data/Gemfile +9 -2
  6. data/Gemfile.mongoid-2.4 +22 -0
  7. data/Gemfile.mongoid-2.5 +22 -0
  8. data/Gemfile.mongoid-2.6 +22 -0
  9. data/Gemfile.mongoid-2.7 +22 -0
  10. data/Gemfile.mongoid-2.8 +22 -0
  11. data/Gemfile.mongoid-3.0 +22 -0
  12. data/Gemfile.mongoid-3.1 +22 -0
  13. data/Gemfile.rails-3.0 +21 -0
  14. data/Gemfile.rails-3.1 +21 -0
  15. data/Gemfile.rails-3.2 +21 -0
  16. data/Gemfile.rails-4.0 +21 -0
  17. data/{Gemfile.rails-3.0.20 → Gemfile.rails-4.1} +1 -1
  18. data/README.md +25 -24
  19. data/Rakefile +13 -6
  20. data/bullet.gemspec +1 -1
  21. data/lib/bullet/active_record41.rb +97 -0
  22. data/lib/bullet/dependency.rb +11 -1
  23. data/lib/bullet/mongoid4x.rb +1 -1
  24. data/lib/bullet/registry/base.rb +1 -1
  25. data/lib/bullet/version.rb +1 -1
  26. data/lib/bullet.rb +1 -1
  27. data/spec/bullet/detector/association_spec.rb +8 -8
  28. data/spec/bullet/detector/base_spec.rb +1 -1
  29. data/spec/bullet/detector/counter_cache_spec.rb +12 -12
  30. data/spec/bullet/detector/n_plus_one_query_spec.rb +32 -32
  31. data/spec/bullet/detector/unused_eager_loading_spec.rb +18 -18
  32. data/spec/bullet/ext/object_spec.rb +2 -2
  33. data/spec/bullet/ext/string_spec.rb +2 -2
  34. data/spec/bullet/notification/base_spec.rb +19 -13
  35. data/spec/bullet/notification/counter_cache_spec.rb +2 -2
  36. data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
  37. data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
  38. data/spec/bullet/notification_collector_spec.rb +4 -4
  39. data/spec/bullet/rack_spec.rb +21 -21
  40. data/spec/bullet/registry/association_spec.rb +3 -3
  41. data/spec/bullet/registry/base_spec.rb +6 -6
  42. data/spec/bullet/registry/object_spec.rb +2 -2
  43. data/spec/integration/active_record3/association_spec.rb +107 -107
  44. data/spec/integration/active_record4/association_spec.rb +105 -105
  45. data/spec/integration/counter_cache_spec.rb +4 -4
  46. data/spec/integration/mongoid/association_spec.rb +52 -52
  47. data/spec/spec_helper.rb +0 -1
  48. data/test.sh +12 -11
  49. metadata +27 -40
  50. data/.ruby-gemset +0 -1
  51. data/.ruby-version +0 -1
  52. data/Gemfile.lock +0 -160
  53. data/Gemfile.mongoid-2.4.12 +0 -15
  54. data/Gemfile.mongoid-2.4.12.lock +0 -163
  55. data/Gemfile.mongoid-2.5.2 +0 -15
  56. data/Gemfile.mongoid-2.5.2.lock +0 -163
  57. data/Gemfile.mongoid-2.6.0 +0 -15
  58. data/Gemfile.mongoid-2.6.0.lock +0 -163
  59. data/Gemfile.mongoid-2.7.1 +0 -15
  60. data/Gemfile.mongoid-2.7.1.lock +0 -163
  61. data/Gemfile.mongoid-2.8.1 +0 -15
  62. data/Gemfile.mongoid-2.8.1.lock +0 -166
  63. data/Gemfile.mongoid-3.0.23 +0 -15
  64. data/Gemfile.mongoid-3.0.23.lock +0 -163
  65. data/Gemfile.mongoid-3.1.5 +0 -15
  66. data/Gemfile.mongoid-3.1.5.lock +0 -163
  67. data/Gemfile.mongoid.lock +0 -167
  68. data/Gemfile.rails-3.0.20.lock +0 -147
  69. data/Gemfile.rails-3.1.12 +0 -14
  70. data/Gemfile.rails-3.1.12.lock +0 -157
  71. data/Gemfile.rails-3.2.15 +0 -14
  72. data/Gemfile.rails-3.2.15.lock +0 -155
  73. data/Gemfile.rails-4.0.1 +0 -14
  74. data/Gemfile.rails-4.0.1.lock +0 -150
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04c7b4ccf13c0c17abfc2372d3d543f1195ba4ac
4
- data.tar.gz: 71ab59fc2ebe3a2a51c77307f817b74aa5a4c601
3
+ metadata.gz: 4ebb362baca8a029544d754fed872a09f7033377
4
+ data.tar.gz: f12124695713d21526305a4c381160048cdc93d6
5
5
  SHA512:
6
- metadata.gz: e5393d00b0a8f45977c7bd0695e55e12d57abd49f07fa22db185a2678a88d88c67596515a3ac97c7c077237d6c51832a3372caa3ecdcfb17d61bd41044e3b123
7
- data.tar.gz: 25938fefe651d07838c8dc2f98785194ed2b48f7c6eb333be6b0029fd74a6fc8aeb3b85b7795cb5eed89d3d8d21d52b98b7ffea11ab1092551ad730748353dd8
6
+ metadata.gz: 7aac621e2ddb3931bb385017401121641027980ebddf0d82d1b43c9a71040a7c2eba3af2c4cb7862d69f9c31c99ac1e124f6a60bd9be6e8388199c187effc98f
7
+ data.tar.gz: 721e946c60ebc8de7bd6c609abb90a9fd29c5c4df2ac275b8bb607e64cffcd86887fa7fc0c82fdd86303faf77d251519b49314dc9af1032131af039b9fd5f868
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ benchmark_profile*
11
11
  /nbproject/private/
12
12
  coverage/
13
13
  .coveralls.yml
14
+ Gemfile*.lock
data/.travis.yml CHANGED
@@ -1,20 +1,20 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.1.0
4
4
  gemfile:
5
- - Gemfile.rails-4.0.1
6
- - Gemfile.rails-3.2.15
7
- - Gemfile.rails-3.1.12
8
- - Gemfile.rails-3.0.20
9
- - Gemfile.mongoid-3.1.5
10
- - Gemfile.mongoid-3.0.23
11
- - Gemfile.mongoid-2.7.1
12
- - Gemfile.mongoid-2.8.1
13
- - Gemfile.mongoid-2.6.0
14
- - Gemfile.mongoid-2.5.2
15
- - Gemfile.mongoid-2.4.12
16
- env: DB=sqlite
17
- services: mongodb
18
- before_install:
19
- - gem uninstall json
20
- - gem install bundler
5
+ - Gemfile.rails-4.1
6
+ - Gemfile.rails-4.0
7
+ - Gemfile.rails-3.2
8
+ - Gemfile.rails-3.1
9
+ - Gemfile.rails-3.0
10
+ - Gemfile.mongoid-3.1
11
+ - Gemfile.mongoid-3.0
12
+ - Gemfile.mongoid-2.8
13
+ - Gemfile.mongoid-2.7
14
+ - Gemfile.mongoid-2.6
15
+ - Gemfile.mongoid-2.5
16
+ - Gemfile.mongoid-2.4
17
+ env:
18
+ - DB=sqlite
19
+ services:
20
+ - mongodb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Next Release
2
2
 
3
+ ## 4.8.0 (02/16/2014)
4
+
5
+ * Support rails 4.1.0.beta1
6
+ * Update specs to be RSepc 3.0 compatible
7
+ * Update latest minor version activerecord and mongoid on travis
8
+
9
+ ## 4.7.0 (11/03/2013)
10
+
11
+ * Add coverall support
12
+ * Add helper to profile code outside a request
13
+ * Add activesupport dependency
14
+ * Add Bullet.raise notification
15
+ * Add Bullet.add_footer notification
16
+ * Fix activerecord4 warnings in test code
17
+
3
18
  ## 4.6.0 (04/18/2013)
4
19
 
5
20
  * Fix Bullet::Rack to support sinatra
data/Gemfile CHANGED
@@ -3,8 +3,10 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', github: 'rails/rails'
6
- gem 'sqlite3'
7
- gem 'mysql2'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
8
10
  gem 'activerecord-import'
9
11
 
10
12
  gem "rspec"
@@ -12,3 +14,8 @@ gem "guard"
12
14
  gem "guard-rspec"
13
15
 
14
16
  gem 'coveralls', require: false
17
+
18
+ platforms :rbx do
19
+ gem 'rubysl', '~> 2.0'
20
+ gem 'rubinius-developer_tools'
21
+ end
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.2.16'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+ gem 'mongoid', '~> 2.4.12'
12
+
13
+ gem "rspec"
14
+ gem "guard"
15
+ gem "guard-rspec"
16
+
17
+ gem 'coveralls', require: false
18
+
19
+ platforms :rbx do
20
+ gem 'rubysl', '~> 2.0'
21
+ gem 'rubinius-developer_tools'
22
+ end
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.2.16'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+ gem 'mongoid', '~> 2.5.2'
12
+
13
+ gem "rspec"
14
+ gem "guard"
15
+ gem "guard-rspec"
16
+
17
+ gem 'coveralls', require: false
18
+
19
+ platforms :rbx do
20
+ gem 'rubysl', '~> 2.0'
21
+ gem 'rubinius-developer_tools'
22
+ end
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.2.16'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+ gem 'mongoid', '~> 2.6.0'
12
+
13
+ gem "rspec"
14
+ gem "guard"
15
+ gem "guard-rspec"
16
+
17
+ gem 'coveralls', require: false
18
+
19
+ platforms :rbx do
20
+ gem 'rubysl', '~> 2.0'
21
+ gem 'rubinius-developer_tools'
22
+ end
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.2.16'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+ gem 'mongoid', '~> 2.7.1'
12
+
13
+ gem "rspec"
14
+ gem "guard"
15
+ gem "guard-rspec"
16
+
17
+ gem 'coveralls', require: false
18
+
19
+ platforms :rbx do
20
+ gem 'rubysl', '~> 2.0'
21
+ gem 'rubinius-developer_tools'
22
+ end
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.2'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+ gem 'mongoid', '~> 2.8'
12
+
13
+ gem "rspec"
14
+ gem "guard"
15
+ gem "guard-rspec"
16
+
17
+ gem 'coveralls', require: false
18
+
19
+ platforms :rbx do
20
+ gem 'rubysl', '~> 2.0'
21
+ gem 'rubinius-developer_tools'
22
+ end
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.2.16'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+ gem 'mongoid', '~> 3.0.23'
12
+
13
+ gem "rspec"
14
+ gem "guard"
15
+ gem "guard-rspec"
16
+
17
+ gem 'coveralls', require: false
18
+
19
+ platforms :rbx do
20
+ gem 'rubysl', '~> 2.0'
21
+ gem 'rubinius-developer_tools'
22
+ end
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.2.16'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+ gem 'mongoid', '~> 3.1.6'
12
+
13
+ gem "rspec"
14
+ gem "guard"
15
+ gem "guard-rspec"
16
+
17
+ gem 'coveralls', require: false
18
+
19
+ platforms :rbx do
20
+ gem 'rubysl', '~> 2.0'
21
+ gem 'rubinius-developer_tools'
22
+ end
data/Gemfile.rails-3.0 ADDED
@@ -0,0 +1,21 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.0.20'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+
12
+ gem "rspec"
13
+ gem "guard"
14
+ gem "guard-rspec"
15
+
16
+ gem 'coveralls', require: false
17
+
18
+ platforms :rbx do
19
+ gem 'rubysl', '~> 2.0'
20
+ gem 'rubinius-developer_tools'
21
+ end
data/Gemfile.rails-3.1 ADDED
@@ -0,0 +1,21 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.1.12'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+
12
+ gem "rspec"
13
+ gem "guard"
14
+ gem "guard-rspec"
15
+
16
+ gem 'coveralls', require: false
17
+
18
+ platforms :rbx do
19
+ gem 'rubysl', '~> 2.0'
20
+ gem 'rubinius-developer_tools'
21
+ end
data/Gemfile.rails-3.2 ADDED
@@ -0,0 +1,21 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 3.2.15'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+
12
+ gem "rspec"
13
+ gem "guard"
14
+ gem "guard-rspec"
15
+
16
+ gem 'coveralls', require: false
17
+
18
+ platforms :rbx do
19
+ gem 'rubysl', '~> 2.0'
20
+ gem 'rubinius-developer_tools'
21
+ end
data/Gemfile.rails-4.0 ADDED
@@ -0,0 +1,21 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 4.0.1'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mysql2', platforms: [:ruby]
9
+ gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
10
+ gem 'activerecord-import'
11
+
12
+ gem "rspec"
13
+ gem "guard"
14
+ gem "guard-rspec"
15
+
16
+ gem 'coveralls', require: false
17
+
18
+ platforms :rbx do
19
+ gem 'rubysl', '~> 2.0'
20
+ gem 'rubinius-developer_tools'
21
+ end
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '3.0.20'
5
+ gem 'rails', '4.1.0.beta1'
6
6
  gem 'sqlite3'
7
7
  gem 'mysql2'
8
8
  gem 'activerecord-import'
data/README.md CHANGED
@@ -3,14 +3,14 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/bullet.png)](http://badge.fury.io/rb/bullet)
4
4
  [![Build Status](https://secure.travis-ci.org/flyerhzm/bullet.png)](http://travis-ci.org/flyerhzm/bullet)
5
5
  [![Coverage Status](https://coveralls.io/repos/flyerhzm/bullet/badge.png?branch=master)](https://coveralls.io/r/flyerhzm/bullet)
6
-
6
+ <a href="https://codeclimate.com/github/flyerhzm/bullet"><img src="https://codeclimate.com/github/flyerhzm/bullet.png" /></a>
7
7
  [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
8
8
 
9
9
  The Bullet gem 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), when you're using eager loading that isn't necessary and when you should use counter cache.
10
10
 
11
11
  Best practice is to use Bullet in development mode or custom mode (staging, profile, etc.). The last thing you want is your clients getting alerts about how lazy you are.
12
12
 
13
- Bullet gem now supports **activerecord** 3.0, 3.1, 3.2, 4.0 and **mongoid** >= 2.4.1.
13
+ Bullet gem now supports **activerecord** >= 3.0 and **mongoid** >= 2.4.1.
14
14
 
15
15
  If you use activercord 2.x, please use bullet <= 4.5.0
16
16
 
@@ -27,7 +27,6 @@ You can install it as a gem:
27
27
 
28
28
  ```
29
29
  gem install bullet
30
-
31
30
  ```
32
31
 
33
32
  or add it into a Gemfile (Bundler):
@@ -138,40 +137,42 @@ If you find bullet does not work for you, *please disable your browser's cache*.
138
137
 
139
138
  ## Advanced
140
139
 
141
- The bullet gem uses rack middleware to profile requests. If you want to use bullet without an http server, like to profile a job, you can do this:
140
+ ### Profile a job
141
+
142
+ The bullet gem uses rack middleware to profile requests. If you want to use bullet without an http server, like to profile a job, you can use use profile method and fetch warnings
142
143
 
143
144
  ```ruby
144
145
  Bullet.profile do
145
- # run job
146
+ # do anything
146
147
  end
148
+ warnings = Bullet.warnings
147
149
  ```
148
150
 
149
- Or to use it in test mode:
151
+ ### Run in tests
150
152
 
151
- ```ruby
152
- before(:each)
153
- Bullet.start_request if Bullet.enable?
154
- end
153
+ First you need to enable bullet in test environment.
155
154
 
156
- after(:each)
157
- if Bullet.enable? && Bullet.notification?
158
- Bullet.perform_out_of_channel_notifications
159
- end
160
- Bullet.end_request if Bullet.enable?
155
+ ```ruby
156
+ # config/environments/test.rb
157
+ config.after_initialize do
158
+ Bullet.enable = true
159
+ Bullet.bullet_logger = true
160
+ Bullet.raise = true # raise an error if n+1 query occurs
161
161
  end
162
162
  ```
163
163
 
164
- Don't forget to enable bullet in your test environment.
165
-
166
- ### API access
167
-
168
- after `profile`, you can fetch warnings then do whatever you want
164
+ Then wrap each test in bullet api.
169
165
 
170
166
  ```ruby
171
- Bullet.profile do
172
- # run anything
167
+ # spec/spec_helper.rb
168
+ before(:each) do
169
+ Bullet.start_request if Bullet.enable?
170
+ end
171
+
172
+ after(:each) do
173
+ Bullet.perform_out_of_channel_notifications if Bullet.enable? && Bullet.notification?
174
+ Bullet.end_request if Bullet.enable?
173
175
  end
174
- warnings = Bullet.warnings
175
176
  ```
176
177
 
177
178
  ## Contributors
@@ -402,4 +403,4 @@ In the meanwhile, there's a log appended into `log/bullet.log` file.
402
403
  ```
403
404
 
404
405
 
405
- Copyright (c) 2009 - 2013 Richard Huang (flyerhzm@gmail.com), released under the MIT license
406
+ Copyright (c) 2009 - 2014 Richard Huang (flyerhzm@gmail.com), released under the MIT license
data/Rakefile CHANGED
@@ -3,7 +3,6 @@ require "bundler"
3
3
  Bundler.setup
4
4
 
5
5
  require "rake"
6
- require "rdoc/task"
7
6
  require "rspec"
8
7
  require "rspec/core/rake_task"
9
8
 
@@ -35,11 +34,19 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
35
34
  spec.pattern = "spec/**/*_spec.rb"
36
35
  end
37
36
 
38
- Rake::RDocTask.new do |rdoc|
39
- rdoc.rdoc_dir = "rdoc"
40
- rdoc.title = "bullet #{Bullet::VERSION}"
41
- rdoc.rdoc_files.include("README*")
42
- rdoc.rdoc_files.include("lib/**/*.rb")
37
+
38
+ begin
39
+ require 'rdoc/task'
40
+
41
+ desc "Generate documentation for the plugin."
42
+ Rake::RDocTask.new do |rdoc|
43
+ rdoc.rdoc_dir = "rdoc"
44
+ rdoc.title = "bullet #{Bullet::VERSION}"
45
+ rdoc.rdoc_files.include("README*")
46
+ rdoc.rdoc_files.include("lib/**/*.rb")
47
+ end
48
+ rescue LoadError
49
+ puts 'RDocTask is not supported for this platform'
43
50
  end
44
51
 
45
52
  task :default => :spec
data/bullet.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.required_rubygems_version = ">= 1.3.6"
17
17
 
18
18
  s.add_dependency "activesupport"
19
- s.add_dependency "uniform_notifier", ">= 1.3.0"
19
+ s.add_dependency "uniform_notifier", ">= 1.4.0"
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
22
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -0,0 +1,97 @@
1
+ module Bullet
2
+ module ActiveRecord
3
+ def self.enable
4
+ require 'active_record'
5
+ ::ActiveRecord::Relation.class_eval do
6
+ alias_method :origin_to_a, :to_a
7
+ # if select a collection of objects, then these objects have possible to cause N+1 query.
8
+ # if select only one object, then the only one object has impossible to cause N+1 query.
9
+ def to_a
10
+ records = origin_to_a
11
+ if records.first.class.name !~ /^HABTM_/
12
+ if records.size > 1
13
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
14
+ Bullet::Detector::CounterCache.add_possible_objects(records)
15
+ elsif records.size == 1
16
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
17
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
18
+ end
19
+ end
20
+ records
21
+ end
22
+ end
23
+
24
+ ::ActiveRecord::Associations::Preloader.class_eval do
25
+ alias_method :origin_preloaders_on, :preloaders_on
26
+
27
+ def preloaders_on(association, records, scope)
28
+ if records.first.class.name !~ /^HABTM_/
29
+ records.each do |record|
30
+ Bullet::Detector::Association.add_object_associations(record, association)
31
+ end
32
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
33
+ end
34
+ origin_preloaders_on(association, records, scope)
35
+ end
36
+ end
37
+
38
+ ::ActiveRecord::FinderMethods.class_eval do
39
+ # add includes in scope
40
+ alias_method :origin_find_with_associations, :find_with_associations
41
+ def find_with_associations
42
+ records = origin_find_with_associations
43
+ associations = (eager_load_values + includes_values).uniq
44
+ records.each do |record|
45
+ Bullet::Detector::Association.add_object_associations(record, associations)
46
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
47
+ end
48
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
49
+ records
50
+ end
51
+ end
52
+
53
+ ::ActiveRecord::Associations::JoinDependency.class_eval do
54
+ alias_method :origin_construct_model, :construct_model
55
+ # call join associations
56
+ def construct_model(record, node, row, model_cache, id, aliases)
57
+ associations = node.reflection.name
58
+ Bullet::Detector::Association.add_object_associations(record, associations)
59
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
60
+ origin_construct_model(record, node, row, model_cache, id, aliases)
61
+ end
62
+ end
63
+
64
+ ::ActiveRecord::Associations::CollectionAssociation.class_eval do
65
+ # call one to many associations
66
+ alias_method :origin_load_target, :load_target
67
+ def load_target
68
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
69
+ origin_load_target
70
+ end
71
+ end
72
+
73
+ ::ActiveRecord::Associations::SingularAssociation.class_eval do
74
+ # call has_one and belongs_to associations
75
+ alias_method :origin_reader, :reader
76
+ def reader(force_reload = false)
77
+ result = origin_reader(force_reload)
78
+ if @owner.class.name !~ /^HABTM_/
79
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
80
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
81
+ end
82
+ result
83
+ end
84
+ end
85
+
86
+ ::ActiveRecord::Associations::HasManyAssociation.class_eval do
87
+ alias_method :origin_has_cached_counter?, :has_cached_counter?
88
+
89
+ def has_cached_counter?(reflection = reflection)
90
+ result = origin_has_cached_counter?(reflection)
91
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
92
+ result
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -18,8 +18,10 @@ module Bullet
18
18
  'active_record3'
19
19
  elsif active_record31? || active_record32?
20
20
  'active_record3x'
21
- elsif active_record4?
21
+ elsif active_record40?
22
22
  'active_record4'
23
+ elsif active_record41?
24
+ 'active_record41'
23
25
  end
24
26
  end
25
27
  end
@@ -56,6 +58,14 @@ module Bullet
56
58
  active_record3? && ::ActiveRecord::VERSION::MINOR == 2
57
59
  end
58
60
 
61
+ def active_record40?
62
+ active_record4? && ::ActiveRecord::VERSION::MINOR == 0
63
+ end
64
+
65
+ def active_record41?
66
+ active_record4? && ::ActiveRecord::VERSION::MINOR == 1
67
+ end
68
+
59
69
  def mongoid2x?
60
70
  mongoid? && ::Mongoid::VERSION =~ /\A2\.[4-8]/
61
71
  end
@@ -44,7 +44,7 @@ module Bullet
44
44
  alias_method :origin_set_relation, :set_relation
45
45
 
46
46
  def set_relation(name, relation)
47
- if relation && relation.metadata.macro !~ /embed/
47
+ if relation && relation.relation_metadata.macro !~ /embed/
48
48
  Bullet::Detector::NPlusOneQuery.call_association(self, name)
49
49
  end
50
50
  origin_set_relation(name, relation)
@@ -33,7 +33,7 @@ module Bullet
33
33
  end
34
34
 
35
35
  def include?(key, value)
36
- @registry[key] && @registry[key].include?(value)
36
+ !@registry[key].nil? && @registry[key].include?(value)
37
37
  end
38
38
  end
39
39
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.7.0"
3
+ VERSION = "4.8.0"
4
4
  end
data/lib/bullet.rb CHANGED
@@ -66,7 +66,7 @@ module Bullet
66
66
 
67
67
  def add_whitelist(options)
68
68
  @whitelist[options[:type]][options[:class_name].classify] ||= []
69
- @whitelist[options[:type]][options[:class_name].classify] << options[:association].to_s.tableize.to_sym
69
+ @whitelist[options[:type]][options[:class_name].classify] << options[:association]
70
70
  end
71
71
 
72
72
  def get_whitelist_associations(type, class_name)