bullet 4.13.1 → 4.13.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4c663f19d349dc9be3a82803ba5e5af344ed0e2
4
- data.tar.gz: f996a53cd2ce05eb85f11e55477b41d7b6f841f8
3
+ metadata.gz: f86ed6daca5c6d8250ec8a65e94ed03b0d598aa3
4
+ data.tar.gz: e8e5ed2f2a88d15ade728ac1b44679a65ad53fb0
5
5
  SHA512:
6
- metadata.gz: 9fe6ad4a5e0b23c19815a121e8b3dec2989c04f2e81836eba4a096a06b68ae7b33c7c202c1a7a99e697a48bd5bd29711b7ad0a2b17e1d203e32cc964a0e95314
7
- data.tar.gz: 77e4bc950eaa4e0e87fd32beaa6f11a605e1e443b0de0f3fbea89798cd11721c3c6a4fa0c9f70bad5c3b7f65586a56b050e38265a21d57d57244e219ab0f8501
6
+ metadata.gz: 286a823bc5003cad396122ca6905953c2e10349436bd61212c2c8437c4e518acf71bb13885e1d66bd01c17785fa16d9a1c201ce874357aad01ab64580064a82c
7
+ data.tar.gz: e7184a6dda78c58b6544f32eca6c917324ba6b9a05108f94755caebbaad4d5b63a51367f76fde1d8abc1b64e920c220772c3773f5be13f4167f56b9df1e12e09
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1.2
4
4
  gemfile:
5
+ - Gemfile.rails-4.2
5
6
  - Gemfile.rails-4.1
6
7
  - Gemfile.rails-4.0
7
8
  - Gemfile.rails-3.2
@@ -1,5 +1,10 @@
1
1
  # Next Release
2
2
 
3
+ ## 4.13.2
4
+
5
+ * Fix warning: `*' interpreted as argument prefix
6
+ * Polish notification output
7
+
3
8
  ## 4.13.1
4
9
 
5
10
  * Fix swallow exception issue
@@ -0,0 +1,19 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 4.2.0.beta'
6
+ gem 'sqlite3'
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'activerecord-import'
9
+
10
+ gem "rspec"
11
+ gem "guard"
12
+ gem "guard-rspec"
13
+
14
+ gem 'coveralls', require: false
15
+
16
+ platforms :rbx do
17
+ gem 'rubysl', '~> 2.0'
18
+ gem 'rubinius-developer_tools'
19
+ end
@@ -153,7 +153,7 @@ module Bullet
153
153
 
154
154
  def perform_out_of_channel_notifications(env = {})
155
155
  for_each_active_notifier_with_notification do |notification|
156
- notification.url = [env['HTTP_HOST'], env['REQUEST_URI']].compact.join
156
+ notification.url = env['REQUEST_URI']
157
157
  notification.notify_out_of_channel
158
158
  end
159
159
  end
@@ -0,0 +1,128 @@
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
+ records.compact!
29
+ if records.first.class.name !~ /^HABTM_/
30
+ records.each do |record|
31
+ Bullet::Detector::Association.add_object_associations(record, association)
32
+ end
33
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
34
+ end
35
+ origin_preloaders_on(association, records, scope)
36
+ end
37
+ end
38
+
39
+ ::ActiveRecord::FinderMethods.class_eval do
40
+ # add includes in scope
41
+ alias_method :origin_find_with_associations, :find_with_associations
42
+ def find_with_associations
43
+ records = origin_find_with_associations
44
+ associations = (eager_load_values + includes_values).uniq
45
+ records.each do |record|
46
+ Bullet::Detector::Association.add_object_associations(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_instantiate, :instantiate
55
+ alias_method :origin_construct_model, :construct_model
56
+
57
+ def instantiate(result_set, aliases)
58
+ @bullet_eager_loadings = {}
59
+ records = origin_instantiate(result_set, aliases)
60
+
61
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
62
+ objects = eager_loadings_hash.keys
63
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
64
+ end
65
+ records
66
+ end
67
+
68
+ # call join associations
69
+ def construct_model(record, node, row, model_cache, id, aliases)
70
+ result = origin_construct_model(record, node, row, model_cache, id, aliases)
71
+
72
+ associations = node.reflection.name
73
+ Bullet::Detector::Association.add_object_associations(record, associations)
74
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
75
+ @bullet_eager_loadings[record.class] ||= {}
76
+ @bullet_eager_loadings[record.class][record] ||= Set.new
77
+ @bullet_eager_loadings[record.class][record] << associations
78
+
79
+ result
80
+ end
81
+ end
82
+
83
+ ::ActiveRecord::Associations::CollectionAssociation.class_eval do
84
+ # call one to many associations
85
+ alias_method :origin_load_target, :load_target
86
+ def load_target
87
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
88
+ origin_load_target
89
+ end
90
+
91
+ alias_method :origin_empty?, :empty?
92
+ def empty?
93
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
94
+ origin_empty?
95
+ end
96
+
97
+ alias_method :origin_include?, :include?
98
+ def include?(object)
99
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
100
+ origin_include?(object)
101
+ end
102
+ end
103
+
104
+ ::ActiveRecord::Associations::SingularAssociation.class_eval do
105
+ # call has_one and belongs_to associations
106
+ alias_method :origin_reader, :reader
107
+ def reader(force_reload = false)
108
+ result = origin_reader(force_reload)
109
+ if @owner.class.name !~ /^HABTM_/
110
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
111
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
112
+ end
113
+ result
114
+ end
115
+ end
116
+
117
+ ::ActiveRecord::Associations::HasManyAssociation.class_eval do
118
+ alias_method :origin_has_cached_counter?, :has_cached_counter?
119
+
120
+ def has_cached_counter?(reflection = reflection())
121
+ result = origin_has_cached_counter?(reflection)
122
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
123
+ result
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -22,6 +22,8 @@ module Bullet
22
22
  'active_record4'
23
23
  elsif active_record41?
24
24
  'active_record41'
25
+ elsif active_record42?
26
+ 'active_record42'
25
27
  end
26
28
  end
27
29
  end
@@ -66,6 +68,10 @@ module Bullet
66
68
  active_record4? && ::ActiveRecord::VERSION::MINOR == 1
67
69
  end
68
70
 
71
+ def active_record42?
72
+ active_record4? && ::ActiveRecord::VERSION::MINOR == 2
73
+ end
74
+
69
75
  def mongoid2x?
70
76
  mongoid? && ::Mongoid::VERSION =~ /\A2\.[4-8]/
71
77
  end
@@ -47,7 +47,7 @@ module Bullet
47
47
  end
48
48
  end
49
49
 
50
- eager_loadings.add *to_add if to_add
50
+ eager_loadings.add(*to_add) if to_add
51
51
  to_merge.each { |k,val| eager_loadings.merge k, val }
52
52
  to_delete.each { |k| eager_loadings.delete k }
53
53
 
@@ -18,6 +18,10 @@ module Bullet
18
18
  raise NoMethodError.new("no method body defined")
19
19
  end
20
20
 
21
+ def call_stack_messages
22
+ ""
23
+ end
24
+
21
25
  def whoami
22
26
  @user ||= ENV['USER'].presence || (`whoami`.chomp rescue "")
23
27
  if @user.present?
@@ -28,15 +32,7 @@ module Bullet
28
32
  end
29
33
 
30
34
  def body_with_caller
31
- body
32
- end
33
-
34
- def standard_notice
35
- @standard_notifice ||= title + "\n" + body
36
- end
37
-
38
- def full_notice
39
- [whoami.presence, url, title, body_with_caller].compact.join("\n")
35
+ "#{body}\n#{call_stack_messages}\n"
40
36
  end
41
37
 
42
38
  def notify_inline
@@ -48,7 +44,7 @@ module Bullet
48
44
  end
49
45
 
50
46
  def short_notice
51
- [whoami.presence, url, title, body].compact.join("\n")
47
+ [whoami.presence, url, title, body].compact.join(" ")
52
48
  end
53
49
 
54
50
  def notification_data
@@ -7,10 +7,6 @@ module Bullet
7
7
  @callers = callers
8
8
  end
9
9
 
10
- def body_with_caller
11
- "#{body}\n#{call_stack_messages}"
12
- end
13
-
14
10
  def body
15
11
  "#{klazz_associations_str}\n Add to your finder: #{associations_str}"
16
12
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.13.1"
3
+ VERSION = "4.13.2"
4
4
  end
data/test.sh CHANGED
@@ -1,5 +1,6 @@
1
1
  #bundle update rails && bundle exec rspec spec
2
2
  #BUNDLE_GEMFILE=Gemfile.mongoid bundle update mongoid && BUNDLE_GEMFILE=Gemfile.mongoid bundle exec rspec spec
3
+ BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle exec rspec spec
3
4
  BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle exec rspec spec
4
5
  BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle exec rspec spec
5
6
  BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle exec rspec spec
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: 4.13.1
4
+ version: 4.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-03 00:00:00.000000000 Z
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -64,6 +64,7 @@ files:
64
64
  - Gemfile.rails-3.2
65
65
  - Gemfile.rails-4.0
66
66
  - Gemfile.rails-4.1
67
+ - Gemfile.rails-4.2
67
68
  - Guardfile
68
69
  - Hacking.md
69
70
  - MIT-LICENSE
@@ -75,6 +76,7 @@ files:
75
76
  - lib/bullet/active_record3x.rb
76
77
  - lib/bullet/active_record4.rb
77
78
  - lib/bullet/active_record41.rb
79
+ - lib/bullet/active_record42.rb
78
80
  - lib/bullet/dependency.rb
79
81
  - lib/bullet/detector.rb
80
82
  - lib/bullet/detector/association.rb