redis_selector 0.0.1 → 0.1.0

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.
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in redis_selector/.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "rspec", "~>2.6"
8
+ gem "rake"
9
+ end
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'bundler/setup'
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = %w(-fs --color)
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ end
9
+
10
+ task :default => :spec
@@ -18,8 +18,10 @@ module RedisSelector
18
18
  end
19
19
 
20
20
  def self.unmock!
21
+ require 'redis'
21
22
  self.mocking = false
22
23
  end
24
+ unmock!
23
25
 
24
26
  def self.configure(config)
25
27
  self.config = config
@@ -36,7 +38,10 @@ module RedisSelector
36
38
  redis_selector = Module.nesting[0]
37
39
 
38
40
  config = redis_selector.config || {}
39
- redis_info = config[what] || config['default'] || DEFAULT_REDIS
41
+ redis_info = (config[what] || config['default'] || DEFAULT_REDIS).
42
+ inject({}) do |opts, (k, v)|
43
+ opts.merge!(k.to_sym => v)
44
+ end
40
45
 
41
46
  redis = if redis_selector.mocking
42
47
  # A MockRedis instance doesn't persist anywhere once we
@@ -44,12 +49,11 @@ module RedisSelector
44
49
  # does. That's why we hold onto this mock like this;
45
50
  # otherwise, repeated calls to with_redis(:foo) each get
46
51
  # a completely empty mock.
47
- redis_selector.mock_redises[redis_info['host']] ||= MockRedis.new
52
+ redis_selector.mock_redises[redis_info[:host]] ||= MockRedis.new(redis_info)
48
53
  else
49
- Redis.new(:host => redis_info['host'])
54
+ Redis.new(redis_info)
50
55
  end
51
56
 
52
- redis.select(redis_info['db']) if redis_info['db']
53
57
  result = yield redis
54
58
  result
55
59
  ensure
@@ -1,3 +1,3 @@
1
1
  module RedisSelector
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.rubyforge_project = "redis_selector"
19
19
 
20
+ s.add_dependency "redis"
21
+
20
22
  s.files = `git ls-files`.split("\n")
21
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -0,0 +1,47 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
2
+ require 'redis_selector'
3
+
4
+ class RedisUser
5
+ extend RedisSelector
6
+
7
+ def self.use_redis(what)
8
+ with_redis(what) {|r| true}
9
+ end
10
+ end
11
+
12
+ describe "RedisSelector" do
13
+ it "works without being configured" do
14
+ Redis.should_receive(:new).with(:host => 'localhost')
15
+ RedisUser.use_redis(:something)
16
+ end
17
+ end
18
+
19
+ describe "RedisSelector" do
20
+ before do
21
+ RedisSelector.configure(
22
+ :leaderboards => {
23
+ :host => 'redisbox',
24
+ :timeout => 30,
25
+ :color => 'blue',
26
+ },
27
+ :stringkeys => {
28
+ 'host' => 'localhost',
29
+ 'db' => 1,
30
+ })
31
+ end
32
+
33
+ it "passes along arbitrary options" do
34
+ Redis.should_receive(:new).with(
35
+ :host => 'redisbox',
36
+ :timeout => 30,
37
+ :color => 'blue')
38
+ RedisUser.use_redis(:leaderboards)
39
+ end
40
+
41
+ it "converts keys to symbols" do
42
+ Redis.should_receive(:new).with(
43
+ :host => 'localhost',
44
+ :db => 1)
45
+ RedisUser.use_redis(:stringkeys)
46
+ end
47
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_selector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Samuel Merritt
@@ -15,10 +15,23 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-08 00:00:00 -07:00
18
+ date: 2011-09-22 00:00:00 -07:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ name: redis
32
+ prerelease: false
33
+ type: :runtime
34
+ version_requirements: *id001
22
35
  description: "Lets you select different Redis instances/databases easily.\n This way, you get logical grouping of different Redis datasets.\n\n Also supports mocking in test mode (via mock_redis gem).\n "
23
36
  email:
24
37
  - spam@andcheese.org
@@ -34,10 +47,10 @@ files:
34
47
  - README.md
35
48
  - Rakefile
36
49
  - lib/redis_selector.rb
37
- - lib/redis_selector/.rb
38
50
  - lib/redis_selector/version.rb
39
51
  - redis_selector.gemspec
40
52
  - redis_selector/.gemspec
53
+ - spec/redis_selector_spec.rb
41
54
  has_rdoc: true
42
55
  homepage: ""
43
56
  licenses: []
@@ -72,5 +85,5 @@ rubygems_version: 1.3.7
72
85
  signing_key:
73
86
  specification_version: 3
74
87
  summary: Easy way to select different Redis instances/databases based on purpose.
75
- test_files: []
76
-
88
+ test_files:
89
+ - spec/redis_selector_spec.rb
@@ -1,5 +0,0 @@
1
- require "redis_selector//version"
2
-
3
- module RedisSelector/
4
- # Your code goes here...
5
- end