redis-classy 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/redis_classy.rb +11 -5
- data/lib/redis_classy/version.rb +1 -1
- data/spec/redis_classy_spec.rb +14 -0
- data/spec/spec_helper.rb +1 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d643329ea57aefcf21b2d5f82e10dc2ceb06153
|
4
|
+
data.tar.gz: 0ee4d20cad2936c1dfb51af9916e2bc7a100cc4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1f69e41172233934e798c9207bbd3e44b6e6f8d7d5e9767747507b2b8ab900a52274b1ca3c991584ba26a52fd202c68c3a762064ed23d9b3f481d4a391f1363
|
7
|
+
data.tar.gz: 4b31213c6d961b7520faa62bf38fc1fb0aa69e98ea645536c70834d9bb46dbdaf1f7644be742f1e6b5a6f178c2ac35b2089da30695661683c1dbdb24309ab8f0
|
data/CHANGELOG.md
CHANGED
data/lib/redis_classy.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
class RedisClassy
|
2
2
|
class << self
|
3
|
-
|
3
|
+
attr_writer :redis
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
5
|
+
def redis
|
6
|
+
@redis ||= begin
|
7
|
+
if self == RedisClassy
|
8
|
+
nil
|
9
|
+
else
|
10
|
+
raise Error.new('RedisClassy.redis is not assigned') if RedisClassy.redis.nil?
|
11
|
+
Redis::Namespace.new(self.name, redis: RedisClassy.redis)
|
12
|
+
end
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
def singletons(*args)
|
@@ -20,7 +26,7 @@ class RedisClassy
|
|
20
26
|
end
|
21
27
|
|
22
28
|
def keys(pattern = nil)
|
23
|
-
|
29
|
+
redis.keys(pattern || '*')
|
24
30
|
end
|
25
31
|
|
26
32
|
def on(key)
|
data/lib/redis_classy/version.rb
CHANGED
data/spec/redis_classy_spec.rb
CHANGED
@@ -13,6 +13,20 @@ describe RedisClassy do
|
|
13
13
|
RedisClassy.redis.quit
|
14
14
|
end
|
15
15
|
|
16
|
+
it 'raises RedisClassy::Error when connection is missing' do
|
17
|
+
begin
|
18
|
+
backup = RedisClassy.redis
|
19
|
+
RedisClassy.redis = nil
|
20
|
+
|
21
|
+
class NoConnection < RedisClassy
|
22
|
+
end
|
23
|
+
|
24
|
+
expect{ NoConnection.keys }.to raise_error(RedisClassy::Error)
|
25
|
+
ensure
|
26
|
+
RedisClassy.redis = backup
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
16
30
|
it 'stores redis or redis-namespace' do
|
17
31
|
expect(RedisClassy.redis.is_a?(Redis)).to be_truthy
|
18
32
|
expect(RedisClassy.redis.is_a?(Redis::Namespace)).to be_falsy
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,6 @@ RSpec.configure do |config|
|
|
8
8
|
# Use database 15 for testing so we don't accidentally step on you real data.
|
9
9
|
RedisClassy.redis = Redis.new(db: 15)
|
10
10
|
unless RedisClassy.keys.empty?
|
11
|
-
|
12
|
-
exit!
|
11
|
+
abort '[ERROR]: Redis database 15 not empty! If you are sure, run "rake flushdb" beforehand.'
|
13
12
|
end
|
14
13
|
end
|