cacchern 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/README.md +3 -3
- data/cacchern.gemspec +1 -0
- data/lib/cacchern/object.rb +24 -22
- data/lib/cacchern/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e98c80d7d12702ba8082334fdf009962d9cb4d543d0833b9b6f1f3a5bde6df6a
|
4
|
+
data.tar.gz: bdb2122e7434eb424d2770186c75cacecc156d1ffbd38eee41f599afcf818679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 347941b61293a7b477766307fc2f6de78aff640c4726f7bba716fb1c9cb640ba608ac1ce77c388cfd648cfd283f742d6e292731dda52cf0564e222dfc136026d
|
7
|
+
data.tar.gz: f93206a531858ef8f29c8a50f91731291a27684e44cd93bc91f07370f6a773aa9822dde00c4ebbd479280cd3bc3f28fe26100804ef39ef999b1dedeb3a6e0652
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,16 +22,16 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
1. Create classes
|
24
24
|
|
25
|
-
Create class that overrides Cacchern::
|
25
|
+
Create class that overrides Cacchern::SortableMember
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
class Score < Cacchern::
|
28
|
+
class Score < Cacchern::SortableMember
|
29
29
|
validates :key, presence: true, numericality: { only_integer: true }
|
30
30
|
validates :value, presence: true, numericality: true
|
31
31
|
end
|
32
32
|
```
|
33
33
|
|
34
|
-
Create class that overrides Cacchern::
|
34
|
+
Create class that overrides Cacchern::SortableMember
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
class ScoreSet < Cacchern::SortedSet
|
data/cacchern.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
25
|
spec.add_development_dependency 'activemodel'
|
26
|
+
spec.add_development_dependency 'activesupport'
|
26
27
|
spec.add_development_dependency 'bundler'
|
27
28
|
spec.add_development_dependency 'rake'
|
28
29
|
spec.add_development_dependency 'redis', '~> 4.0.0'
|
data/lib/cacchern/object.rb
CHANGED
@@ -4,48 +4,50 @@ module Cacchern
|
|
4
4
|
class Object
|
5
5
|
include ActiveModel::Model
|
6
6
|
|
7
|
+
class << self
|
8
|
+
def key(id)
|
9
|
+
"#{name.underscore}:#{id}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(id)
|
13
|
+
key = self.key(id)
|
14
|
+
value = Redis.current.get(key)
|
15
|
+
|
16
|
+
new(id, value) if value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
attr_reader :id
|
8
21
|
attr_reader :key
|
9
22
|
attr_reader :value
|
10
23
|
|
11
|
-
define_model_callbacks :save
|
12
|
-
before_save { throw(:abort) unless valid? }
|
13
|
-
|
14
24
|
def initialize(id, value)
|
15
25
|
@id = id
|
16
26
|
@key = "#{self.class.name.underscore}:#{id}"
|
17
27
|
@value = value
|
18
28
|
end
|
19
29
|
|
20
|
-
def save
|
21
|
-
|
30
|
+
def save(options = {})
|
31
|
+
expires_in = options[:expires_in]
|
32
|
+
valid? ? create_or_update(expires_in) : false
|
22
33
|
end
|
23
34
|
|
24
|
-
def save!
|
25
|
-
|
35
|
+
def save!(options = {})
|
36
|
+
save(options) || raise_validation_error
|
26
37
|
end
|
27
38
|
|
28
39
|
def delete
|
29
40
|
Redis.current.del(key)
|
30
41
|
end
|
31
42
|
|
32
|
-
class << self
|
33
|
-
def key(id)
|
34
|
-
"#{name.underscore}:#{id}"
|
35
|
-
end
|
36
|
-
|
37
|
-
def find(id)
|
38
|
-
key = self.key(id)
|
39
|
-
value = Redis.current.get(key)
|
40
|
-
|
41
|
-
new(id, value) if value
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
43
|
private
|
46
44
|
|
47
|
-
def create_or_update
|
48
|
-
|
45
|
+
def create_or_update(expires_in = nil)
|
46
|
+
if expires_in
|
47
|
+
Redis.current.setex(key, expires_in.to_i, value)
|
48
|
+
else
|
49
|
+
Redis.current.set(key, value) == 'OK'
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
data/lib/cacchern/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cacchern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shuhei TAKASUGI
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|