activerecord-delay_touching 0.0.4 → 1.0.0

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: 81d58f8a4a53021f8034c2da68790d7648b2b4f3
4
- data.tar.gz: 2d975e4e5c14ee8baecaaf762aaa8a8ebb003bef
3
+ metadata.gz: bf2e396443031e052664ae33fa9abca71b1a1b45
4
+ data.tar.gz: 0009099d96abdb6f58a1590c5f5c7df699d0382e
5
5
  SHA512:
6
- metadata.gz: 46209cc3478f9f81e932644e79364bb2ff012d536cabc2e3927cca61c74a641b0b9fc94e6522574c2c0c21281e1a0fda4df0be6db40c0f58b001d73c7ead5008
7
- data.tar.gz: 89654bba87280ab7976c0d464d43f4a9e0760643ce614532c12910b4e9b9602b38635815251bde5877bbd24a2c95742ca13ffac0b55bb7461a1786c0e5c077a7
6
+ metadata.gz: bba9504122174575808beec7d1107e603e434535afe421361dd83ad6341867fbdae957e509653349be3a7ebd16c97050d4c12ca900aa22360a547c61a017d2cd
7
+ data.tar.gz: 2e822052fb026400b9abd0b9bb25a36220d9eac30acb02267495535b9da99fc3be49e1cd296e6c035ccdd0c97c12c00fe51636d38f3f64664048a4fcb5f6863b
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Activerecord::DelayTouching
2
2
 
3
- > **Note:** this version supports ActiveRecord 3.2 through 4.1 only. For ActiveRecord 4.2+, please see the Master branch.
4
-
5
3
  Batch up your ActiveRecord "touch" operations for better performance.
6
4
 
7
5
  When you want to invalidate a cache in Rails, you use `touch: true`. But when
@@ -15,7 +13,7 @@ round-trips as possible. Instead of N touches you get 1 touch.
15
13
 
16
14
  Add this line to your application's Gemfile:
17
15
 
18
- gem 'activerecord-delay_touching', '~> 0.0.3'
16
+ gem 'activerecord-delay_touching'
19
17
 
20
18
  And then execute:
21
19
 
@@ -23,7 +21,7 @@ And then execute:
23
21
 
24
22
  Or install it yourself:
25
23
 
26
- $ gem install activerecord-delay_touching -v 0.0.3
24
+ $ gem install activerecord-delay_touching
27
25
 
28
26
  ## Usage
29
27
 
@@ -13,14 +13,12 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
16
- spec.required_ruby_version = ">= 1.9.3"
17
-
18
16
  spec.files = `git ls-files -z`.split("\x0")
19
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
19
  spec.require_paths = ["lib"]
22
20
 
23
- spec.add_dependency "activerecord", ">= 3.2", "< 4.2"
21
+ spec.add_dependency "activerecord", ">= 4.2"
24
22
 
25
23
  spec.add_development_dependency "bundler", "~> 1.6"
26
24
  spec.add_development_dependency "rake"
@@ -6,9 +6,9 @@ module ActiveRecord
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  # Override ActiveRecord::Base#touch.
9
- def touch(name = nil)
10
- if self.class.delay_touching? && (!respond_to?(:no_touching?) || !try(:no_touching?))
11
- DelayTouching.add_record(self, name)
9
+ def touch(*names)
10
+ if self.class.delay_touching? && !try(:no_touching?)
11
+ DelayTouching.add_record(self, *names)
12
12
  true
13
13
  else
14
14
  super
@@ -41,8 +41,8 @@ module ActiveRecord
41
41
  Thread.current[:delay_touching_state] ||= State.new
42
42
  end
43
43
 
44
- def self.add_record(record, column)
45
- state.add_record(record, column)
44
+ class << self
45
+ delegate :add_record, to: :state
46
46
  end
47
47
 
48
48
  # Start delaying all touches. When done, apply them. (Unless nested.)
@@ -86,7 +86,6 @@ module ActiveRecord
86
86
  column = column.to_s
87
87
  changes[column] = current_time
88
88
  records.each do |record|
89
- next if record.destroyed?
90
89
  record.instance_eval do
91
90
  write_attribute column, current_time
92
91
  @changed_attributes.except!(*changes.keys)
@@ -102,6 +101,4 @@ module ActiveRecord
102
101
  end
103
102
  end
104
103
 
105
- ActiveRecord::Base.class_eval do
106
- include ActiveRecord::DelayTouching
107
- end
104
+ ActiveRecord::Base.include ActiveRecord::DelayTouching
@@ -37,14 +37,18 @@ module ActiveRecord
37
37
  @records.present?
38
38
  end
39
39
 
40
- def add_record(record, column)
41
- @records[column] += [ record ] unless @already_updated_records[column].include?(record)
40
+ def add_record(record, *columns)
41
+ columns << nil if columns.empty? #if no arguments are passed, we will use nil to infer default column
42
+ columns.each do |column|
43
+ @records[column] += [ record ] unless @already_updated_records[column].include?(record)
44
+ end
42
45
  end
43
46
 
44
47
  def clear_records
45
48
  @records.clear
46
49
  @already_updated_records.clear
47
50
  end
51
+
48
52
  end
49
53
  end
50
54
  end
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module DelayTouching
3
- VERSION = "0.0.4"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -151,28 +151,6 @@ describe Activerecord::DelayTouching do
151
151
  end
152
152
  end
153
153
 
154
- context 'dependent deletes' do
155
-
156
- let(:post) { Post.create! }
157
- let(:user) { User.create! }
158
- let(:comment) { Comment.create! }
159
-
160
- before do
161
- post.comments << comment
162
- user.comments << comment
163
- end
164
-
165
- it 'does not attempt to touch deleted records' do
166
- expect do
167
- ActiveRecord::Base.delay_touching do
168
- post.destroy
169
- end
170
- end.not_to raise_error
171
- expect(post.destroyed?).to eq true
172
- end
173
-
174
- end
175
-
176
154
  def expect_updates(tables)
177
155
  expected_sql = tables.map do |entry|
178
156
  if entry.kind_of?(Hash)
@@ -5,16 +5,3 @@ end
5
5
  class Pet < ActiveRecord::Base
6
6
  belongs_to :person, touch: true, inverse_of: :pets
7
7
  end
8
-
9
- class Post < ActiveRecord::Base
10
- has_many :comments, dependent: :destroy
11
- end
12
-
13
- class User < ActiveRecord::Base
14
- has_many :comments, dependent: :destroy
15
- end
16
-
17
- class Comment < ActiveRecord::Base
18
- belongs_to :post, touch: true
19
- belongs_to :user, touch: true
20
- end
@@ -16,18 +16,4 @@ ActiveRecord::Schema.define do
16
16
  t.timestamps
17
17
  end
18
18
 
19
- create_table :posts, force: true do |t|
20
- t.timestamps null: false
21
- end
22
-
23
- create_table :users, force: true do |t|
24
- t.timestamps null: false
25
- end
26
-
27
- create_table :comments, force: true do |t|
28
- t.integer :post_id
29
- t.integer :user_id
30
- t.timestamps null: false
31
- end
32
-
33
19
  end
metadata CHANGED
@@ -1,23 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-delay_touching
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Morearty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-08 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '3.2'
20
- - - "<"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '4.2'
23
20
  type: :runtime
@@ -25,9 +22,6 @@ dependencies:
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '3.2'
30
- - - "<"
31
25
  - !ruby/object:Gem::Version
32
26
  version: '4.2'
33
27
  - !ruby/object:Gem::Dependency
@@ -178,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
172
  requirements:
179
173
  - - ">="
180
174
  - !ruby/object:Gem::Version
181
- version: 1.9.3
175
+ version: '0'
182
176
  required_rubygems_version: !ruby/object:Gem::Requirement
183
177
  requirements:
184
178
  - - ">="
@@ -186,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
180
  version: '0'
187
181
  requirements: []
188
182
  rubyforge_project:
189
- rubygems_version: 2.4.8
183
+ rubygems_version: 2.4.6
190
184
  signing_key:
191
185
  specification_version: 4
192
186
  summary: Batch up your ActiveRecord "touch" operations for better performance.