cache_associations 0.3.1 → 0.3.2

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: cd12d459e007b638dd6288d6e78831ae230e8233
4
- data.tar.gz: e6d9d9823b011d71ad13b06f25235710870380a1
3
+ metadata.gz: 8f3c9a712f9405d1416e18af9ce780fac80f199f
4
+ data.tar.gz: 3e9ce36be672bb9d7334130b474bfe3a9413a482
5
5
  SHA512:
6
- metadata.gz: df3c9ec190039a151c008d6fb5f2787e30a4750b33a60118e189ce3f7f8780aaf5c063109905e21aa7e19bda501791aa84aa6b2967d4bcc9fbe04a699d634178
7
- data.tar.gz: 97560d261ba269437bc73f72fe8b2a478bf199fccb8c72e2f551fa813d30b188e5c2e3df23bcb39efb2f93449cb097ced438272581d3a856b1c281b47806b12c
6
+ metadata.gz: ec1a1351dd9fc79dc788b0af27e1a49044a08e24d7897cf9b2b773592139d24d0401385b5c2db6a57702a6098a404c58ec1799b1e5cf136865aae198a191b228
7
+ data.tar.gz: 7229a72a7c0eae3f476f36a1279103dc242a4120322e87ee6a1b24df2b315a95028dbb9871a8b5e419a6a09947fef1e1617329d037401748e2b8ce5b191e582e
data/README.md CHANGED
@@ -39,7 +39,7 @@ class User < ApplicationRecord
39
39
 
40
40
  # you do not need to provide a block to specify the cache
41
41
  # name, this will provide you a default name composed of
42
- # [self.class.reflect_on_association(name).klass.name, id]
42
+ # [reflection.klass.name, send(reflection.foreign_key)]
43
43
  cache_global_association :profile
44
44
 
45
45
  def factorial_1000
@@ -73,7 +73,7 @@ irb> u.clear_caching_on_association(:profile) # clear the cache
73
73
  You may customize what the data you cached, the cached method accepts an optional block that determines how to cache data.
74
74
  But it will break the original association, so you should be careful with this feature.
75
75
 
76
- ```
76
+ ```ruby
77
77
  irb> u = User.take
78
78
  irb> u.cached_profile do "gotcha" end
79
79
  => "gotcha"
@@ -19,6 +19,8 @@ module CacheAssociations
19
19
  options = Rails.cache.options.merge(options)
20
20
 
21
21
  define_method("cached_#{name}") do |*args, &block|
22
+ break send(name) unless association_instance_get(name).nil?
23
+
22
24
  cache_name = cache_name_block.nil? ? default_cache_name(name) : instance_exec(&cache_name_block)
23
25
  cache = Rails.cache.fetch(cache_name, **options) do
24
26
  break instance_exec(*args, &block) if !block.nil?
@@ -1,3 +1,3 @@
1
1
  module CacheAssociations
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fuxin Hao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-10 00:00:00.000000000 Z
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails