counter_culture 2.2.4 → 2.3.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
  SHA256:
3
- metadata.gz: 1aa4340620f0ec34dbb3c5509ef3390eaffde8c280d9cdc06c11ba842367c33f
4
- data.tar.gz: ab9934d186e52e271ff2b5b09cc85927892c7b9c5e8e18220bc4e2dda56dd918
3
+ metadata.gz: c8bc293e01a8e0b0f05d3d183092552f8136e76f7d08145aa354e0dc7c2693ba
4
+ data.tar.gz: 905edad7a81274176e100eaa58b5ee798d985c97f4c6543dee7b6fe81fd57675
5
5
  SHA512:
6
- metadata.gz: 6d9dfd7a08e7b68e8d4d00b731fe6ca27d78fc51e060992c60b494cbb0853c29f57a8d2373fc5ed8b2442b44c1e7ed1952c3a4eccda15244c66a4f652bf841a5
7
- data.tar.gz: 1f197ae5fa09c9044557790a0d2e7f2b61ae5d3dd3352dc7c5cbc1bc6164d9e8dfa3401084c544a708a43c750705e1f80af1530d4166c226335610bfbfc6907c
6
+ metadata.gz: 723cc217870d0640c81f94c692604b260dfa1c45b747693807bbd8f5ceb5557c01398bbe4f9313a844a430b685eee25c9910a2360ffddd124c4d8c759ce72689
7
+ data.tar.gz: bdcf5cef68f33898f535a976a642fa1b4f1397a496f23e2519c35076935b5fe431e58b7a810ee243ef89596ada2f40dd522642233e46f50b395626d32142f727
@@ -6,9 +6,9 @@ addons:
6
6
  postgresql: "9.6"
7
7
  rvm:
8
8
  - "2.3.8"
9
- - "2.4.6"
10
- - "2.5.5"
11
- - "2.6.3"
9
+ - "2.4.7"
10
+ - "2.5.6"
11
+ - "2.6.4"
12
12
  gemfile:
13
13
  - gemfiles/rails_4.2.gemfile
14
14
  - gemfiles/rails_5.0.gemfile
@@ -23,7 +23,7 @@ matrix:
23
23
  exclude:
24
24
  - rvm: "2.3.8"
25
25
  gemfile: gemfiles/rails_6.0.gemfile
26
- - rvm: "2.4.6"
26
+ - rvm: "2.4.7"
27
27
  gemfile: gemfiles/rails_6.0.gemfile
28
28
  before_install:
29
29
  - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
@@ -1,3 +1,8 @@
1
+ ## 2.3.0 (January 28, 2020)
2
+
3
+ Improvements:
4
+ - Allow using scopes in `column_names` (#272)
5
+
1
6
  ## 2.2.4 (August 21, 2019)
2
7
 
3
8
  Bugfixes:
data/README.md CHANGED
@@ -7,7 +7,7 @@ Turbo-charged counter caches for your Rails app. Huge improvements over the Rail
7
7
  * Supports dynamic column names, making it possible to split up the counter cache for different types of objects
8
8
  * Can keep a running count, or a running total
9
9
 
10
- Tested against Ruby 2.3.8, 2.4.6, 2.5.5 and 2.6.2 and against the latest patch releases of Rails 4.2, 5.0, 5.1 and 5.2.
10
+ Tested against Ruby 2.3.8, 2.4.7, 2.5.6 and 2.6.4 and against the latest patch releases of Rails 4.2, 5.0, 5.1, 5.2 and 6.0.
11
11
 
12
12
  Please note that -- unlike Rails' built-in counter-caches -- counter_culture does not currently change the behavior of the `.size` method on ActiveRecord associations. If you want to avoid a database query and read the cached value, please use the attribute name containing the counter cache directly.
13
13
  ```
@@ -329,6 +329,23 @@ class Product < ActiveRecord::Base
329
329
  end
330
330
  ```
331
331
 
332
+ You can specify a scope instead of a where condition string for `column_names`:
333
+
334
+ ```ruby
335
+ class Product < ActiveRecord::Base
336
+ belongs_to :category
337
+ scope :awesomes, ->{ where "products.product_type = ?", 'awesome' }
338
+ scope :suckys, ->{ where "products.product_type = ?", 'sucky' }
339
+
340
+ counter_culture :category,
341
+ column_name: proc {|model| "#{model.product_type}_count" },
342
+ column_names: {
343
+ Product.awesomes => :awesome_count,
344
+ Product.suckys => :sucky_count
345
+ }
346
+ end
347
+ ```
348
+
332
349
  If you would like to avoid this configuration and simply skip counter caches with
333
350
  dynamic column names, while still fixing those counters on the model that are not
334
351
  dynamic, you can pass `skip_unsupported`:
@@ -252,7 +252,11 @@ module CounterCulture
252
252
  if index == reverse_relation.size - 1
253
253
  # conditions must be applied to the join on which we are counting
254
254
  if where
255
- joins_sql += " AND (#{model.send(:sanitize_sql_for_conditions, where)})"
255
+ if where.respond_to?(:to_sql)
256
+ joins_sql += " AND #{target_table_alias}.#{model.primary_key} IN (#{where.select(model.primary_key).to_sql})"
257
+ else
258
+ joins_sql += " AND (#{model.send(:sanitize_sql_for_conditions, where)})"
259
+ end
256
260
  end
257
261
  # respect the deleted_at column if it exists
258
262
  if model.column_names.include?('deleted_at')
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '2.2.4'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
@@ -3,7 +3,7 @@
3
3
  set -e
4
4
  source /usr/local/share/chruby/chruby.sh
5
5
 
6
- for RUBY_VERSION in 2.3.8 2.4.6 2.5.5 2.6.2; do
6
+ for RUBY_VERSION in 2.3.8 2.4.7 2.5.6 2.6.4; do
7
7
  chruby $RUBY_VERSION
8
8
  ruby --version
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counter_culture
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.4
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus von Koeller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-22 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: after_commit_action
@@ -304,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
304
304
  - !ruby/object:Gem::Version
305
305
  version: '0'
306
306
  requirements: []
307
- rubygems_version: 3.0.3
307
+ rubygems_version: 3.1.2
308
308
  signing_key:
309
309
  specification_version: 4
310
310
  summary: Turbo-charged counter caches for your Rails app.