attr_cached 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/init.rb +1 -0
- data/lib/attr_cached.rb +28 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 725c00a3036d232745250c074f0a603d81fbb869
|
4
|
+
data.tar.gz: 7ac7ae8b8f038ec2a6a5ed073fc7c1e86040fda5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74c642d81ccc69ef3bb13eb14ec935b20c63c8ed7e11dcdc1ceff4949870b02d8043786d5ba47ef9c06ab8dffe4470661f391c97948cd14624ecb97c63281e1c
|
7
|
+
data.tar.gz: 76b92da130d9a2e5c5af854c5ca566bfaa8fda97e35d0426bc381b59712ff9864246a96f2c0e3cf336062f86f220d99dd14bac5924a6e3062daf66c402cb6d26
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'attr_cached'
|
data/lib/attr_cached.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
|
3
|
+
# The attr_cached method should be called in the body of an
|
4
|
+
# ActiveRecord model which has an 'id' attribute.
|
5
|
+
def self.attr_cached *attributes
|
6
|
+
# Iterate through each attribute
|
7
|
+
attributes.each do |attribute|
|
8
|
+
# Set the beginning to the key to be used in both the read and write methods.
|
9
|
+
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
|
+
|
14
|
+
# Define the method to read from the cache
|
15
|
+
define_method attribute do
|
16
|
+
raise missing_id if id.nil?
|
17
|
+
Rails.cache.read(key + id.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Define the method to write to the cache
|
21
|
+
define_method "#{attribute}=" do |value|
|
22
|
+
raise missing_id if id.nil?
|
23
|
+
Rails.cache.write(key + id.to_s, value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attr_cached
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Swan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: michael@michaelswan.io
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/attr_cached.rb
|
20
|
+
- init.rb
|
21
|
+
homepage: http://github.com/swanyboy2/attr_cached
|
22
|
+
licenses: []
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Defines a named attribute for an ActiveRecord model that stores its content
|
44
|
+
in the Rails cache.
|
45
|
+
test_files: []
|