cached_counts 0.2.5 → 0.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
  SHA1:
3
- metadata.gz: 94fd9b8e942d4db45453d60bada7562222aa6939
4
- data.tar.gz: dc02fc2fb8eec7c6f6650c15e917062336d7f09c
3
+ metadata.gz: 099b873eefb8c41c66af75ec703e7c8363044ff0
4
+ data.tar.gz: 26e85dc0d9b81e1147723aefd69c0c3480c55709
5
5
  SHA512:
6
- metadata.gz: df76d8899468ebcbb0ef1b9fe18019a48ba61648aa84e1f5f4ea243cf3798291d561dc286eee743d99cb52be9400cfc03c008b8e8c8360492a9a6ae40bda29c8
7
- data.tar.gz: 2e9ecf36881e6dbd26a63e9cd06b5fd622f4fb9d111353075c8665952b7a3ff58461576434623eaf033fda1df6a459f4398f2d402a17c5d8f697b3a3de2f877c
6
+ metadata.gz: 6fbf0c99ac1d1b46df366a15badba40338febabc5268db6f8a978e4140b53956c53213c2b0d548e9839655a682c5e3823c443aec8964ed0cb97f86e00ee81c88
7
+ data.tar.gz: 080e32b056397811ad1749d8a108ec78ff9a37fd1000fd3f4d12b4fbb68bc4cd8a31094f09ac49eaf7788c5e7793a8c3e1de0e734e1625908fa695ea33e0cb7b
data/README.md CHANGED
@@ -44,6 +44,25 @@ You can also use the non cached count on the class or scopes.
44
44
  User.where(:admin => true).count_without_caching # => Runs a database lookup
45
45
  ```
46
46
 
47
+ ## Usage with Rails
48
+
49
+ If you're using rails you can optionally disable the ovveriding of the `count` `size` and `lenght` methods by setting the `count_with_caching` configuration value.
50
+ You can do so in your application config like so:
51
+
52
+ ```ruby
53
+ # config/application.rb
54
+
55
+ module MyApp
56
+ class Application < Rails::Application
57
+ #...
58
+ config.cache_counts_by_default = false
59
+ #...
60
+ end
61
+ end
62
+ ```
63
+
64
+ Disabling the cache by default allows you to use `MyModel.count_with_caching` to return the cached count value.
65
+
47
66
  ## Clearing the cache
48
67
 
49
68
  The counts cache is cleared for a model after save and after destroy.
@@ -5,9 +5,16 @@ module CachedCounts
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- alias_method_chain :count, :caching
9
- alias_method_chain :length, :caching
10
- alias_method_chain :size, :caching
8
+ if defined?(Rails) && Rails.configuration.respond_to?(:cache_counts_by_default) && Rails.configuration.cache_counts_by_default
9
+ alias_method_chain :count, :caching
10
+ alias_method_chain :length, :caching
11
+ alias_method_chain :size, :caching
12
+ else
13
+ # Existing code calls count_without_caching, so just make it a no-op
14
+ alias_method :count_without_caching, :count
15
+ alias_method :length_without_caching, :length
16
+ alias_method :size_without_caching, :size
17
+ end
11
18
  end
12
19
 
13
20
  def count_with_caching(*args)
@@ -1,3 +1,3 @@
1
1
  module CachedCounts
2
- VERSION = '0.2.5'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cached_counts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Visic