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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43bc9e17910f065ef35c2be995966f0714ce4ea1
4
- data.tar.gz: b7499771aa9b2354c43ea346d8f3878297d66ab6
3
+ metadata.gz: 7d643329ea57aefcf21b2d5f82e10dc2ceb06153
4
+ data.tar.gz: 0ee4d20cad2936c1dfb51af9916e2bc7a100cc4a
5
5
  SHA512:
6
- metadata.gz: 4b7491c74284bdddc17a8f47641813d608beb0dfdd4f02890e7cd79dcb04f51ba8a207cff3784ce09d4dfc3230039db945bf95b849e4b8e605051f503395e9de
7
- data.tar.gz: 1614dd0aaee898bb35b74b2ccfc13d6ff866d01e8479edcdbe7c583ea68b955a2ffadbef83f3f2a953b9fbd75712a3c857f1bb4c47923d790aec3674cf1d5cc8
6
+ metadata.gz: b1f69e41172233934e798c9207bbd3e44b6e6f8d7d5e9767747507b2b8ab900a52274b1ca3c991584ba26a52fd202c68c3a762064ed23d9b3f481d4a391f1363
7
+ data.tar.gz: 4b31213c6d961b7520faa62bf38fc1fb0aa69e98ea645536c70834d9bb46dbdaf1f7644be742f1e6b5a6f178c2ac35b2089da30695661683c1dbdb24309ab8f0
@@ -1,3 +1,7 @@
1
+ ## 2.1.0 2014-11-23
2
+
3
+ * Lazy connection loading
4
+
1
5
  ## 2.0.0 2014-11-23
2
6
 
3
7
  * New feature: `singletons` to support predefined keys
@@ -1,10 +1,16 @@
1
1
  class RedisClassy
2
2
  class << self
3
- attr_accessor :redis
3
+ attr_writer :redis
4
4
 
5
- def inherited(subclass)
6
- raise Error.new('RedisClassy.redis is not assigned') unless RedisClassy.redis
7
- subclass.redis = Redis::Namespace.new(subclass.name, redis: RedisClassy.redis)
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
- @redis.keys(pattern || '*')
29
+ redis.keys(pattern || '*')
24
30
  end
25
31
 
26
32
  def on(key)
@@ -1,3 +1,3 @@
1
1
  class RedisClassy
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -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
@@ -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
- puts '[ERROR]: Redis database 15 not empty! If you are sure, run "rake flushdb" beforehand.'
12
- exit!
11
+ abort '[ERROR]: Redis database 15 not empty! If you are sure, run "rake flushdb" beforehand.'
13
12
  end
14
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-classy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenn Ejima