bullet 5.4.0 → 5.5.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/test.sh CHANGED
@@ -4,15 +4,6 @@ BUNDLE_GEMFILE=Gemfile.rails-5.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-5.0 bund
4
4
  BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle exec rspec spec
5
5
  BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle exec rspec spec
6
6
  BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle exec rspec spec
7
- BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle exec rspec spec
8
- BUNDLE_GEMFILE=Gemfile.rails-3.1 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.1 bundle exec rspec spec
9
- BUNDLE_GEMFILE=Gemfile.rails-3.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.0 bundle exec rspec spec
7
+ BUNDLE_GEMFILE=Gemfile.mongoid-6.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-6.0 bundle exec rspec spec
10
8
  BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle exec rspec spec
11
9
  BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle exec rspec spec
12
- BUNDLE_GEMFILE=Gemfile.mongoid-3.1 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-3.1 bundle exec rspec spec
13
- BUNDLE_GEMFILE=Gemfile.mongoid-3.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-3.0 bundle exec rspec spec
14
- BUNDLE_GEMFILE=Gemfile.mongoid-2.8 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.8 bundle exec rspec spec
15
- BUNDLE_GEMFILE=Gemfile.mongoid-2.7 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.7 bundle exec rspec spec
16
- BUNDLE_GEMFILE=Gemfile.mongoid-2.6 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.6 bundle exec rspec spec
17
- BUNDLE_GEMFILE=Gemfile.mongoid-2.5 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.5 bundle exec rspec spec
18
- BUNDLE_GEMFILE=Gemfile.mongoid-2.4 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.4 bundle exec rspec spec
data/update.sh CHANGED
@@ -2,15 +2,6 @@ BUNDLE_GEMFILE=Gemfile.rails-5.0 bundle update
2
2
  BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle update
3
3
  BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle update
4
4
  BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle update
5
- BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle update
6
- BUNDLE_GEMFILE=Gemfile.rails-3.1 bundle update
7
- BUNDLE_GEMFILE=Gemfile.rails-3.0 bundle update
5
+ BUNDLE_GEMFILE=Gemfile.mongoid-6.0 bundle update
8
6
  BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle update
9
7
  BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle update
10
- BUNDLE_GEMFILE=Gemfile.mongoid-3.1 bundle update
11
- BUNDLE_GEMFILE=Gemfile.mongoid-3.0 bundle update
12
- BUNDLE_GEMFILE=Gemfile.mongoid-2.8 bundle update
13
- BUNDLE_GEMFILE=Gemfile.mongoid-2.7 bundle update
14
- BUNDLE_GEMFILE=Gemfile.mongoid-2.6 bundle update
15
- BUNDLE_GEMFILE=Gemfile.mongoid-2.5 bundle update
16
- BUNDLE_GEMFILE=Gemfile.mongoid-2.4 bundle update
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.0
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-10 00:00:00.000000000 Z
11
+ date: 2016-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -51,18 +51,9 @@ files:
51
51
  - CHANGELOG.md
52
52
  - Gemfile
53
53
  - Gemfile.mongoid
54
- - Gemfile.mongoid-2.4
55
- - Gemfile.mongoid-2.5
56
- - Gemfile.mongoid-2.6
57
- - Gemfile.mongoid-2.7
58
- - Gemfile.mongoid-2.8
59
- - Gemfile.mongoid-3.0
60
- - Gemfile.mongoid-3.1
61
54
  - Gemfile.mongoid-4.0
62
55
  - Gemfile.mongoid-5.0
63
- - Gemfile.rails-3.0
64
- - Gemfile.rails-3.1
65
- - Gemfile.rails-3.2
56
+ - Gemfile.mongoid-6.0
66
57
  - Gemfile.rails-4.0
67
58
  - Gemfile.rails-4.1
68
59
  - Gemfile.rails-4.2
@@ -74,8 +65,6 @@ files:
74
65
  - Rakefile
75
66
  - bullet.gemspec
76
67
  - lib/bullet.rb
77
- - lib/bullet/active_record3.rb
78
- - lib/bullet/active_record3x.rb
79
68
  - lib/bullet/active_record4.rb
80
69
  - lib/bullet/active_record41.rb
81
70
  - lib/bullet/active_record42.rb
@@ -89,10 +78,9 @@ files:
89
78
  - lib/bullet/detector/unused_eager_loading.rb
90
79
  - lib/bullet/ext/object.rb
91
80
  - lib/bullet/ext/string.rb
92
- - lib/bullet/mongoid2x.rb
93
- - lib/bullet/mongoid3x.rb
94
81
  - lib/bullet/mongoid4x.rb
95
82
  - lib/bullet/mongoid5x.rb
83
+ - lib/bullet/mongoid6x.rb
96
84
  - lib/bullet/notification.rb
97
85
  - lib/bullet/notification/base.rb
98
86
  - lib/bullet/notification/counter_cache.rb
@@ -125,7 +113,6 @@ files:
125
113
  - spec/bullet/registry/base_spec.rb
126
114
  - spec/bullet/registry/object_spec.rb
127
115
  - spec/bullet_spec.rb
128
- - spec/integration/active_record3/association_spec.rb
129
116
  - spec/integration/active_record4/association_spec.rb
130
117
  - spec/integration/active_record5/association_spec.rb
131
118
  - spec/integration/counter_cache_spec.rb
@@ -212,7 +199,6 @@ test_files:
212
199
  - spec/bullet/registry/base_spec.rb
213
200
  - spec/bullet/registry/object_spec.rb
214
201
  - spec/bullet_spec.rb
215
- - spec/integration/active_record3/association_spec.rb
216
202
  - spec/integration/active_record4/association_spec.rb
217
203
  - spec/integration/active_record5/association_spec.rb
218
204
  - spec/integration/counter_cache_spec.rb
data/Gemfile.mongoid-2.5 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 2.5.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.mongoid-2.6 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 2.6.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.mongoid-2.7 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 2.7.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.mongoid-2.8 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 2.8.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.mongoid-3.0 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 3.0.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.mongoid-3.1 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 3.1.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.rails-3.0 DELETED
@@ -1,16 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.0.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'activerecord-import'
9
- gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
-
11
- gem "rspec"
12
-
13
- platforms :rbx do
14
- gem 'rubysl', '~> 2.0'
15
- gem 'rubinius-developer_tools'
16
- end
data/Gemfile.rails-3.1 DELETED
@@ -1,16 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.1.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'activerecord-import'
9
- gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
-
11
- gem "rspec"
12
-
13
- platforms :rbx do
14
- gem 'rubysl', '~> 2.0'
15
- gem 'rubinius-developer_tools'
16
- end
data/Gemfile.rails-3.2 DELETED
@@ -1,16 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'activerecord-import'
9
- gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
-
11
- gem "rspec"
12
-
13
- platforms :rbx do
14
- gem 'rubysl', '~> 2.0'
15
- gem 'rubinius-developer_tools'
16
- end
@@ -1,233 +0,0 @@
1
- module Bullet
2
- module ActiveRecord
3
- LOAD_TARGET = 'load_target'.freeze
4
-
5
- def self.enable
6
- require 'active_record'
7
- ::ActiveRecord::Base.class_eval do
8
- class <<self
9
- alias_method :origin_find_by_sql, :find_by_sql
10
- def find_by_sql(sql)
11
- result = origin_find_by_sql(sql)
12
- if Bullet.start?
13
- if result.is_a? Array
14
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
15
- Bullet::Detector::CounterCache.add_possible_objects(result)
16
- elsif result.is_a? ::ActiveRecord::Base
17
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
18
- Bullet::Detector::CounterCache.add_impossible_object(result)
19
- end
20
- end
21
- result
22
- end
23
- end
24
- end
25
-
26
- ::ActiveRecord::Relation.class_eval do
27
- alias_method :origin_to_a, :to_a
28
- # if select a collection of objects, then these objects have possible to cause N+1 query.
29
- # if select only one object, then the only one object has impossible to cause N+1 query.
30
- def to_a
31
- records = origin_to_a
32
- if Bullet.start?
33
- if records.size > 1
34
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
35
- Bullet::Detector::CounterCache.add_possible_objects(records)
36
- elsif records.size == 1
37
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
38
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
39
- end
40
- end
41
- records
42
- end
43
- end
44
-
45
- ::ActiveRecord::Persistence.class_eval do
46
- alias_method :origin_save, :save
47
- def save(*args, &proc)
48
- was_new_record = new_record?
49
- origin_save(*args, &proc).tap do |result|
50
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
51
- end
52
- end
53
-
54
- alias_method :origin_save!, :save!
55
- def save!(*args, &proc)
56
- was_new_record = new_record?
57
- origin_save!(*args, &proc).tap do |result|
58
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
59
- end
60
- end
61
- end
62
-
63
- ::ActiveRecord::AssociationPreload::ClassMethods.class_eval do
64
- alias_method :origin_preload_associations, :preload_associations
65
- # include query for one to many associations.
66
- # keep this eager loadings.
67
- def preload_associations(records, associations, preload_options={})
68
- if Bullet.start?
69
- records = [records].flatten.compact.uniq
70
- return if records.empty?
71
- records.each do |record|
72
- Bullet::Detector::Association.add_object_associations(record, associations)
73
- end
74
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
75
- end
76
- origin_preload_associations(records, associations, preload_options={})
77
- end
78
- end
79
-
80
- ::ActiveRecord::FinderMethods.class_eval do
81
- # add includes in scope
82
- alias_method :origin_find_with_associations, :find_with_associations
83
- def find_with_associations
84
- records = origin_find_with_associations
85
- if Bullet.start?
86
- associations = (@eager_load_values + @includes_values).uniq
87
- records.each do |record|
88
- Bullet::Detector::Association.add_object_associations(record, associations)
89
- end
90
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
91
- end
92
- records
93
- end
94
- end
95
-
96
- ::ActiveRecord::Associations::ClassMethods::JoinDependency.class_eval do
97
- alias_method :origin_instantiate, :instantiate
98
- alias_method :origin_construct_association, :construct_association
99
-
100
- def instantiate(rows)
101
- @bullet_eager_loadings = {}
102
- records = origin_instantiate(rows)
103
-
104
- if Bullet.start?
105
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
106
- objects = eager_loadings_hash.keys
107
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
108
- end
109
- end
110
- records
111
- end
112
-
113
- # call join associations
114
- def construct_association(record, join, row)
115
- result = origin_construct_association(record, join, row)
116
-
117
- if Bullet.start?
118
- associations = join.reflection.name
119
- Bullet::Detector::Association.add_object_associations(record, associations)
120
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
121
- @bullet_eager_loadings[record.class] ||= {}
122
- @bullet_eager_loadings[record.class][record] ||= Set.new
123
- @bullet_eager_loadings[record.class][record] << associations
124
- end
125
-
126
- result
127
- end
128
- end
129
-
130
- ::ActiveRecord::Associations::AssociationCollection.class_eval do
131
- # call one to many associations
132
- alias_method :origin_load_target, :load_target
133
- def load_target
134
- if Bullet.start?
135
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
136
- end
137
- origin_load_target
138
- end
139
-
140
- alias_method :origin_first, :first
141
- def first(*args)
142
- if Bullet.start?
143
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
144
- end
145
- origin_first(*args)
146
- end
147
-
148
- alias_method :origin_last, :last
149
- def last(*args)
150
- if Bullet.start?
151
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
152
- end
153
- origin_last(*args)
154
- end
155
-
156
- alias_method :origin_include?, :include?
157
- def include?(object)
158
- if Bullet.start?
159
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
160
- end
161
- origin_include?(object)
162
- end
163
- end
164
-
165
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
166
- alias_method :origin_empty?, :empty?
167
- def empty?
168
- if Bullet.start? && !has_cached_counter?
169
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
170
- end
171
- origin_empty?
172
- end
173
- end
174
-
175
- ::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
176
- alias_method :origin_empty?, :empty?
177
- def empty?
178
- if Bullet.start?
179
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
180
- end
181
- origin_empty?
182
- end
183
- end
184
-
185
- ::ActiveRecord::Associations::AssociationProxy.class_eval do
186
- # call has_one and belong_to association
187
- alias_method :origin_load_target, :load_target
188
- def load_target
189
- # avoid stack level too deep
190
- result = origin_load_target
191
- if Bullet.start?
192
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?(LOAD_TARGET) }
193
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
194
- end
195
- result
196
- end
197
-
198
- alias_method :origin_set_inverse_instance, :set_inverse_instance
199
- def set_inverse_instance(record, instance)
200
- if Bullet.start?
201
- if record && we_can_set_the_inverse_on_this?(record)
202
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
203
- end
204
- end
205
- origin_set_inverse_instance(record, instance)
206
- end
207
- end
208
-
209
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
210
- alias_method :origin_has_cached_counter?, :has_cached_counter?
211
-
212
- def has_cached_counter?
213
- result = origin_has_cached_counter?
214
- if Bullet.start? && !result
215
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
216
- end
217
- result
218
- end
219
- end
220
-
221
- ::ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
222
- alias_method :origin_has_cached_counter?, :has_cached_counter?
223
- def has_cached_counter?
224
- result = origin_has_cached_counter?
225
- if Bullet.start? && !result
226
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
227
- end
228
- result
229
- end
230
- end
231
- end
232
- end
233
- end