conditional_counter_cache 0.0.2 → 0.0.3

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: 00a4bcb0f63a7936b1f0ccf93a62f88ab2636172
4
- data.tar.gz: ee002eeb7f874e9ca7f31f309ed7fa2437cebcf8
3
+ metadata.gz: 67b6400f57af1be506b76af3618bfe5784328da4
4
+ data.tar.gz: c3a98bbdb52a7a24eaf81617b0a1bec34638617a
5
5
  SHA512:
6
- metadata.gz: 13441a35f7f0c13dfe7b8b30386edadf10244178dc5b44f08eeb1fe7115d3444375e2d48f41904462f88b04781a75ebd02fa550f73776169ce536f43c5564a39
7
- data.tar.gz: bd069a40e093f2785586083894279ef8dd379a2024e7131c3205b3dcedab72178da50fab757cc65041baf1b69df715f33f88cf26cf93deb49a3310a340e0cd03
6
+ metadata.gz: b2f28b4dcb18b32facf8b3a154dce4aa60509b0678e36ea966fd6eb38becb867c0995e18e3a27ff37f1f98259fd560baf6a07a6e50bae51a8454af9b36ebaa24
7
+ data.tar.gz: ec19e146850906ae08b316bf1260ede3947f9e4185cce96fe1780090bee493ec9ee64e3a136d167127dd146d3f7f67ca208968727cfba4f76e2615381ecce50d
@@ -1,5 +1,8 @@
1
+ ## 0.0.3
2
+ - Support Rails 4.2.0
3
+
1
4
  ## 0.0.2
2
- * Fix non counter-cached belongs_to association
5
+ - Fix non counter-cached belongs_to association
3
6
 
4
7
  ## 0.0.1
5
- * 1st release
8
+ - 1st release
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # ConditionalCounterCache
2
- Allows you to customize condition of counter cache.
2
+ Give condition when to increment/decrement counter cache.
3
3
 
4
4
  ## Usage
5
5
  Customize condition via `:counter_cache` option:
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = ConditionalCounterCache::VERSION
9
9
  spec.authors = ["Ryo Nakamura"]
10
10
  spec.email = ["r7kamura@gmail.com"]
11
- spec.summary = "Allows you to customize condition of counter cache."
11
+ spec.summary = "Give condition when to increment/decrement counter cache."
12
12
  spec.homepage = "https://github.com/r7kamura/conditional_counter_cache"
13
13
  spec.license = "MIT"
14
14
 
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "activerecord", ">= 4.0.0", "< 4.2.0"
20
+ spec.add_dependency "activerecord", ">= 4.0.0"
21
21
  spec.add_dependency "activesupport"
22
22
  spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rails"
@@ -1,27 +1,28 @@
1
1
  module ConditionalCounterCache
2
- # Overrides ActiveRecord 4.1.4's counter cache implementation.
3
2
  module BelongsTo
4
3
  def add_counter_cache_methods(mixin)
5
- return if mixin.method_defined? :belongs_to_counter_cache_after_create
4
+ return if mixin.method_defined? :belongs_to_counter_cache_after_update
6
5
 
7
6
  mixin.class_eval do
8
- def belongs_to_counter_cache_after_create(reflection)
9
- if record = send(reflection.name)
10
- return unless reflection.has_countable?(self)
11
- cache_column = reflection.counter_cache_column
12
- record.class.increment_counter(cache_column, record.id)
13
- @_after_create_counter_called = true
14
- end
15
- end
16
-
17
- def belongs_to_counter_cache_before_destroy(reflection)
18
- foreign_key = reflection.foreign_key.to_sym
19
- unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key
20
- record = send reflection.name
21
- if record && !self.destroyed?
7
+ unless ActiveRecord::VERSION::MAJOR >= 4 && ActiveRecord::VERSION::MINOR >= 2
8
+ def belongs_to_counter_cache_after_create(reflection)
9
+ if record = send(reflection.name)
22
10
  return unless reflection.has_countable?(self)
23
11
  cache_column = reflection.counter_cache_column
24
- record.class.decrement_counter(cache_column, record.id)
12
+ record.class.increment_counter(cache_column, record.id)
13
+ @_after_create_counter_called = true
14
+ end
15
+ end
16
+
17
+ def belongs_to_counter_cache_before_destroy(reflection)
18
+ foreign_key = reflection.foreign_key.to_sym
19
+ unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key
20
+ record = send reflection.name
21
+ if record && !self.destroyed?
22
+ return unless reflection.has_countable?(self)
23
+ cache_column = reflection.counter_cache_column
24
+ record.class.decrement_counter(cache_column, record.id)
25
+ end
25
26
  end
26
27
  end
27
28
  end
@@ -1,3 +1,3 @@
1
1
  module ConditionalCounterCache
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conditional_counter_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-07 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.0
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: 4.2.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 4.0.0
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: 4.2.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: activesupport
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -153,9 +147,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
147
  version: '0'
154
148
  requirements: []
155
149
  rubyforge_project:
156
- rubygems_version: 2.2.2
150
+ rubygems_version: 2.4.5
157
151
  signing_key:
158
152
  specification_version: 4
159
- summary: Allows you to customize condition of counter cache.
153
+ summary: Give condition when to increment/decrement counter cache.
160
154
  test_files: []
161
155
  has_rdoc: