counter_culture 3.0.0 → 3.1.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: 6e21168dbc07960cbb457996e275fe225426b9e96cd4b78a7dcd65ac13a0e006
4
- data.tar.gz: 655b861dbd102fd40c0be44fc9f12c5a3a8b21682a8951597c7b4d2bcde3ea5e
3
+ metadata.gz: 461f74df5dfedb6986e9ad3504c20d6a8c173b284011279b853cec7a58fdf57b
4
+ data.tar.gz: ce60aa02f06c3719f2a34020ca065bf6fe07847d7b4e5d238ef263345634e491
5
5
  SHA512:
6
- metadata.gz: 42ae36d35f8ad486b25477a89e87477a40909fb08ffd627c6441c2c4ce17ef038c5f92f3514bd2cc993fd01996f3e49ab2470481f2ab778dc620c2aa7f65d59c
7
- data.tar.gz: 48ad4871eb41b4a97e5f53f41a671e4fef455fa2c70d475002de69bda1db8b1e8cc4af91b0c251d6ac1a4fba961ba5ab3eb2e821f9e9c8735a577728f7270338
6
+ metadata.gz: b706ac60f8dcd3f68e8b7da3a8987caaddfd9d5e0c67cb94923af7188910614c0c991047734e8a4c28d68801e41ab1f77ac975e659615facd6ecdaf96ce58faa
7
+ data.tar.gz: e9b2a3910632ee00a5e6489f339e79f7e3b07be8aee5ef7eddf0e60f82e7af848aedcc63861cf281c833edb9703407ae215fd7b4ea57b792fe74b776ae5a45ca
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 3.1.0 (November 29, 2021)
2
+
3
+ Improvements:
4
+ - Allow specifiying a `Proc` to `column_names` to avoid loading a scope on
5
+ startup (#335)
6
+
1
7
  ## 3.0.0 (October 26, 2021)
2
8
 
3
9
  Breaking changes:
data/README.md CHANGED
@@ -376,7 +376,10 @@ class Product < ActiveRecord::Base
376
376
  end
377
377
  ```
378
378
 
379
- You can specify a scope instead of a where condition string for `column_names`:
379
+ You can specify a scope instead of a where condition string for `column_names`. We recommend
380
+ providing a Proc that returns a hash instead of directly providing a hash: If you were to directly
381
+ provide a scope this would load your schema cache on startup which will break things like
382
+ `rake db:migrate`.
380
383
 
381
384
  ```ruby
382
385
  class Product < ActiveRecord::Base
@@ -386,10 +389,10 @@ class Product < ActiveRecord::Base
386
389
 
387
390
  counter_culture :category,
388
391
  column_name: proc {|model| "#{model.product_type}_count" },
389
- column_names: {
392
+ column_names: -> { {
390
393
  Product.awesomes => :awesome_count,
391
394
  Product.suckys => :sucky_count
392
- }
395
+ } }
393
396
  end
394
397
  ```
395
398
 
@@ -43,4 +43,7 @@ Gem::Specification.new do |spec|
43
43
  spec.add_development_dependency 'rspec-extra-formatters'
44
44
  spec.add_development_dependency 'simplecov', '~> 0.16.1'
45
45
  spec.add_development_dependency 'timecop'
46
+ spec.add_development_dependency 'sqlite3'
47
+ spec.add_development_dependency 'mysql2'
48
+ spec.add_development_dependency 'pg'
46
49
  end
@@ -45,8 +45,19 @@ module CounterCulture
45
45
  @after_commit_counter_cache = []
46
46
  end
47
47
 
48
- if options[:column_names] && !options[:column_names].is_a?(Hash)
49
- raise ":column_names must be a Hash of conditions and column names"
48
+ column_names_valid = (
49
+ !options[:column_names] ||
50
+ options[:column_names].is_a?(Hash) ||
51
+ (
52
+ options[:column_names].is_a?(Proc) &&
53
+ options[:column_names].call.is_a?(Hash)
54
+ )
55
+ )
56
+ unless column_names_valid
57
+ raise ArgumentError.new(
58
+ ":column_names must be a Hash of conditions and column names, " \
59
+ "or a Proc that when called returns such a Hash"
60
+ )
50
61
  end
51
62
 
52
63
  # add the counter to our collection
@@ -74,7 +74,15 @@ module CounterCulture
74
74
 
75
75
  scope = relation_class
76
76
 
77
- counter_column_names = column_names || {nil => counter_cache_name}
77
+ counter_column_names =
78
+ case column_names
79
+ when Proc
80
+ column_names.call
81
+ when Hash
82
+ column_names
83
+ else
84
+ { nil => counter_cache_name }
85
+ end
78
86
 
79
87
  if options[:column_name]
80
88
  counter_column_names = counter_column_names.select{ |_, v| options[:column_name].to_s == v }
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.0.0'.freeze
2
+ VERSION = '3.1.0'.freeze
3
3
  end
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: 3.0.0
4
+ version: 3.1.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: 2021-10-26 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -248,6 +248,48 @@ dependencies:
248
248
  - - ">="
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: sqlite3
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: mysql2
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: pg
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
251
293
  description: counter_culture provides turbo-charged counter caches that are kept up-to-date
252
294
  not just on create and destroy, that support multiple levels of indirection through
253
295
  relationships, allow dynamic column names and that avoid deadlocks by updating in