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 +4 -4
- data/.travis.yml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +18 -1
- data/lib/counter_culture/reconciler.rb +5 -1
- data/lib/counter_culture/version.rb +1 -1
- data/run_tests_locally.sh +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8bc293e01a8e0b0f05d3d183092552f8136e76f7d08145aa354e0dc7c2693ba
|
4
|
+
data.tar.gz: 905edad7a81274176e100eaa58b5ee798d985c97f4c6543dee7b6fe81fd57675
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 723cc217870d0640c81f94c692604b260dfa1c45b747693807bbd8f5ceb5557c01398bbe4f9313a844a430b685eee25c9910a2360ffddd124c4d8c759ce72689
|
7
|
+
data.tar.gz: bdcf5cef68f33898f535a976a642fa1b4f1397a496f23e2519c35076935b5fe431e58b7a810ee243ef89596ada2f40dd522642233e46f50b395626d32142f727
|
data/.travis.yml
CHANGED
@@ -6,9 +6,9 @@ addons:
|
|
6
6
|
postgresql: "9.6"
|
7
7
|
rvm:
|
8
8
|
- "2.3.8"
|
9
|
-
- "2.4.
|
10
|
-
- "2.5.
|
11
|
-
- "2.6.
|
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.
|
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
|
data/CHANGELOG.md
CHANGED
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.
|
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
|
-
|
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')
|
data/run_tests_locally.sh
CHANGED
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.
|
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:
|
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.
|
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.
|