attr_cached 1.2 → 1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/attr_cached.rb +10 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d242c82d648d83b5138bc10af56ecf57dd8c0cdd
4
- data.tar.gz: afa543a7b7797523483bdae99d5d15f423417c2f
3
+ metadata.gz: 1bf28ed293f2b11115936be37caabc5b325247bd
4
+ data.tar.gz: 4069cc845f60b0802b110e100e7b9dccf2001aa7
5
5
  SHA512:
6
- metadata.gz: 72ab6acba13a562b4a4e1d85508abd8043e5a6a50c73ddeeae5f7158075b6964ebb45906e0e9d4c3b9c29bae01356c8b977d71a40c56c029be0745a2acf7d55e
7
- data.tar.gz: f235f9d5dac99d38ee65386998b36046a4697d185903f165efbbdd348162340ef5822a663538329d037d9d67bd05a923d61a430f2344beb527e297a417827573
6
+ metadata.gz: 7b4f4500b830da85c163ec59f2b09bfc91b6ca19d39dab6cf7212781a0807a519fcbc9902ca822fc9ab578f0b21e80da22f381137d45742383f79a3c91755843
7
+ data.tar.gz: aa572f08f82e88f561b7d4b054065cfe8cd09914e548b8be3a5393e234306a4c1882ecb2908ae91b64e90fb521f1f325e35bdc49d1bb9da5f9b15f1be86a6364
@@ -3,13 +3,13 @@ class ActiveRecord::Base
3
3
  # The attr_cached method should be called in the body of an
4
4
  # ActiveRecord model which has an 'id' attribute.
5
5
  def self.attr_cached *attributes
6
+ # Assign a reusable message to raise upon the occurence of a nil id.
7
+ missing_id = 'The \'id\' cannot be nil when calling an attribute created by attr_memcached'
8
+
6
9
  # Iterate through each attribute
7
10
  attributes.each do |attribute|
8
11
  # Set the beginning to the key to be used in both the read and write methods.
9
12
  key = "#{name.downcase}_#{attribute}_"
10
-
11
- # Assign a reusable message to raise upon the occurence of a nil id.
12
- missing_id = 'The \'id\' cannot be nil when calling an attribute created by attr_memcached'
13
13
 
14
14
  # Define the method to read from the cache
15
15
  define_method attribute do
@@ -29,6 +29,13 @@ class ActiveRecord::Base
29
29
  Rails.cache.delete(key + id.to_s)
30
30
  end
31
31
  end
32
+ class_name = "#{name.downcase}_"
33
+ define_method :delete_cache do
34
+ raise missing_id if id.nil?
35
+ attributes.each do |attribute|
36
+ Rails.cache.delete class_name + "#{attribute}_#{id}"
37
+ end
38
+ end
32
39
  end
33
40
 
34
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_cached
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Swan