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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59d307f8d9365a1f5154a2584f58f0b74b09c88a19c5e58d9f7e205692e51d8c
4
- data.tar.gz: 3b83aa1c03998c439e1ee63c0838563eb11e82268933ec53fa5c46d8d393d241
3
+ metadata.gz: e98c80d7d12702ba8082334fdf009962d9cb4d543d0833b9b6f1f3a5bde6df6a
4
+ data.tar.gz: bdb2122e7434eb424d2770186c75cacecc156d1ffbd38eee41f599afcf818679
5
5
  SHA512:
6
- metadata.gz: 230469df9e4bb596d0dac5d15030cb00547b7abf98b818bd2ab9c58c1edc1402b457d6708374646e56d1a0ad02639c2c181f20ca9e4afd54c8c898d0f5592935
7
- data.tar.gz: '025968b870076cb72b696049cc390049045b4d197f17cb2ff1e22d5fde86617cbaa3fdb755f98c66b202836a27e2084199c8dec5eab3cf7bba149e040460abbc'
6
+ metadata.gz: 347941b61293a7b477766307fc2f6de78aff640c4726f7bba716fb1c9cb640ba608ac1ce77c388cfd648cfd283f742d6e292731dda52cf0564e222dfc136026d
7
+ data.tar.gz: f93206a531858ef8f29c8a50f91731291a27684e44cd93bc91f07370f6a773aa9822dde00c4ebbd479280cd3bc3f28fe26100804ef39ef999b1dedeb3a6e0652
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cacchern (0.0.4)
4
+ cacchern (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -61,6 +61,7 @@ PLATFORMS
61
61
 
62
62
  DEPENDENCIES
63
63
  activemodel
64
+ activesupport
64
65
  bundler
65
66
  cacchern!
66
67
  database_cleaner
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::Value
25
+ Create class that overrides Cacchern::SortableMember
26
26
 
27
27
  ```ruby
28
- class Score < Cacchern::Value
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::Value
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'
@@ -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
- valid? ? create_or_update : false
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
- valid? ? create_or_update : raise_validation_error
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
- Redis.current.set(key, value) == 'OK'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cacchern
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
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
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-13 00:00:00.000000000 Z
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