cacchern 0.0.2 → 0.0.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.
- checksums.yaml +4 -4
- data/.rspec +2 -1
- data/.rubocop_todo.yml +5 -3
- data/Gemfile.lock +1 -1
- data/lib/cacchern.rb +2 -0
- data/lib/cacchern/member.rb +17 -0
- data/lib/cacchern/set.rb +39 -0
- data/lib/cacchern/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cada82336b3402cd99bbf835bfd3e6b1bb8188f3481a42832e0221505abb008b
|
4
|
+
data.tar.gz: 64e923503de48ada4e5d4203fb39bb86e4be592bbbbae85f6e88e1fac0dfba74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b36a6076033a42c7f68efbe37cd6497b3ab2bf6c9c70892e37ea1d8aa62d632ccd23223795f182ddc18b81ebfd30ea3f5a8b045a055c97b164ba92e8ea4efd4a
|
7
|
+
data.tar.gz: 7c1c2c95e2270fbdb48cd179325ab63b3bb81932aedf2a0e3396f7e2630e1112ac3325267d32f3d7d47676dbea31508acd41d0cc603df6f7b60a862c4d2bd46c
|
data/.rspec
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2018-09-
|
3
|
+
# on 2018-09-06 16:46:12 +0900 using RuboCop version 0.58.2.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 2
|
10
10
|
# Configuration parameters: CountComments, ExcludedMethods.
|
11
11
|
# ExcludedMethods: refine
|
12
12
|
Metrics/BlockLength:
|
13
13
|
Max: 56
|
14
14
|
|
15
|
-
# Offense count:
|
15
|
+
# Offense count: 6
|
16
16
|
Style/Documentation:
|
17
17
|
Exclude:
|
18
18
|
- 'spec/**/*'
|
19
19
|
- 'test/**/*'
|
20
20
|
- 'lib/cacchern.rb'
|
21
21
|
- 'lib/cacchern/incrementable_sorted_set.rb'
|
22
|
+
- 'lib/cacchern/member.rb'
|
23
|
+
- 'lib/cacchern/set.rb'
|
22
24
|
- 'lib/cacchern/sorted_set.rb'
|
23
25
|
- 'lib/cacchern/value.rb'
|
24
26
|
|
data/Gemfile.lock
CHANGED
data/lib/cacchern.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cacchern
|
4
|
+
class Member
|
5
|
+
include ActiveModel::Model
|
6
|
+
|
7
|
+
attr_reader :value
|
8
|
+
|
9
|
+
define_model_callbacks :initialize
|
10
|
+
before_initialize { throw(:abort) unless valid? }
|
11
|
+
|
12
|
+
def initialize(value)
|
13
|
+
@value = value
|
14
|
+
run_callbacks :initialize
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/cacchern/set.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cacchern/member'
|
4
|
+
|
5
|
+
module Cacchern
|
6
|
+
class Set
|
7
|
+
attr_reader :key
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def contain_class(klass)
|
11
|
+
@value_class = klass
|
12
|
+
end
|
13
|
+
|
14
|
+
def value_class
|
15
|
+
@value_class || Member
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(key)
|
20
|
+
@key = "#{self.class.name.underscore}:#{key}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def all
|
24
|
+
values = Redis.current.smembers @key
|
25
|
+
values.map { |value| self.class.value_class.new(value) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(value)
|
29
|
+
return false unless value.instance_of?(self.class.value_class)
|
30
|
+
|
31
|
+
if value.valid?
|
32
|
+
Redis.current.sadd @key, value.value
|
33
|
+
true
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.3
|
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-09-
|
11
|
+
date: 2018-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -89,6 +89,8 @@ files:
|
|
89
89
|
- cacchern.gemspec
|
90
90
|
- lib/cacchern.rb
|
91
91
|
- lib/cacchern/incrementable_sorted_set.rb
|
92
|
+
- lib/cacchern/member.rb
|
93
|
+
- lib/cacchern/set.rb
|
92
94
|
- lib/cacchern/sorted_set.rb
|
93
95
|
- lib/cacchern/value.rb
|
94
96
|
- lib/cacchern/version.rb
|