norton 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/norton/timed_value.rb +40 -0
- data/lib/norton/version.rb +1 -1
- data/lib/norton.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8032502bd52f644505505f0a4ded443860c9ac1
|
4
|
+
data.tar.gz: 6185c37037b78f70f44ea72c8173ac5a70b6c961
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dae103b58cff40df3761a51af66e74f867c540bbe944ef63a26af39daadbf39c3d4661ecee20393a8448a808ff23428474ef1711fc577c217088844ea744d977
|
7
|
+
data.tar.gz: 8d9b896f3d50974bccecc1379c1d7f1e5cf623537ba6772c0533d251dbff96cb80e5b9a95c9fd3974f50b15e979c7055dc864b850144022259288e7082d30284
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Norton
|
2
|
+
module TimedValue
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def timed_value(name, options={}, &blk)
|
8
|
+
if options[:ttl].nil?
|
9
|
+
raise 'Time to live not specified.'
|
10
|
+
end
|
11
|
+
|
12
|
+
if blk.nil?
|
13
|
+
raise 'Value generation not provided'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Define getter
|
17
|
+
define_method(name) do
|
18
|
+
Norton.redis.with do |conn|
|
19
|
+
v = conn.get("#{self.class.to_s.tableize}:#{self.id}:#{name}")
|
20
|
+
|
21
|
+
if v.nil?
|
22
|
+
v = instance_eval(&blk)
|
23
|
+
conn.setex("#{self.class.to_s.tableize}:#{self.id}:#{name}", options[:ttl], v)
|
24
|
+
end
|
25
|
+
|
26
|
+
v
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method("reset_#{name}") do
|
31
|
+
Norton.redis.with do |conn|
|
32
|
+
v = instance_eval(&blk)
|
33
|
+
conn.setex("#{self.class.to_s.tableize}:#{self.id}:#{name}", options[:ttl], v)
|
34
|
+
v
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/norton/version.rb
CHANGED
data/lib/norton.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- Rakefile
|
138
138
|
- lib/norton.rb
|
139
139
|
- lib/norton/counter.rb
|
140
|
+
- lib/norton/timed_value.rb
|
140
141
|
- lib/norton/timestamp.rb
|
141
142
|
- lib/norton/version.rb
|
142
143
|
- norton.gemspec
|