redis_feature_control 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +24 -0
- data/HISTORY.md +10 -0
- data/README.md +7 -3
- data/Rakefile +4 -41
- data/lib/redis/feature_control.rb +5 -2
- data/lib/redis/feature_control/version.rb +5 -0
- data/test/feature_control_test.rb +72 -59
- data/test/redis-test.conf +2 -2
- data/test/test_helper.rb +5 -1
- metadata +69 -37
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
redis_feature_control (0.0.2)
|
5
|
+
redis (>= 0.1.1)
|
6
|
+
redis-namespace (>= 0.2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
mocha (0.9.12)
|
12
|
+
redis (2.1.1)
|
13
|
+
redis-namespace (0.10.0)
|
14
|
+
redis (< 3.0.0)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (>= 1.0.0)
|
21
|
+
mocha
|
22
|
+
redis (>= 0.1.1)
|
23
|
+
redis-namespace (>= 0.2.0)
|
24
|
+
redis_feature_control!
|
data/HISTORY.md
ADDED
data/README.md
CHANGED
@@ -18,7 +18,11 @@ that job to sometime in the future without having to test the service.
|
|
18
18
|
|
19
19
|
### Usage
|
20
20
|
|
21
|
-
|
21
|
+
Install it:
|
22
|
+
|
23
|
+
gem install redis_feature_control
|
24
|
+
|
25
|
+
Configure it:
|
22
26
|
|
23
27
|
require 'rubygems'
|
24
28
|
require 'redis/feature_control'
|
@@ -38,13 +42,13 @@ Then see if they are enabled and toggle them:
|
|
38
42
|
# disabling...
|
39
43
|
Redis::FeatureControl.disable!(:cc_gateway)
|
40
44
|
Redis::FeatureControl.enabled?(:cc_gateway) # => false
|
41
|
-
Redis::FeatureControl.
|
45
|
+
Redis::FeatureControl.state(:cc_gateway) # => "disabled"
|
42
46
|
|
43
47
|
# enabling...
|
44
48
|
Redis::FeatureControl.enable!(:cc_gateway)
|
45
49
|
Redis::FeatureControl.enabled?(:cc_gateway) # => true
|
46
50
|
Redis::FeatureControl.disabled?(:cc_gateway) # => false
|
47
|
-
Redis::FeatureControl.
|
51
|
+
Redis::FeatureControl.state(:cc_gateway) # => "enabled"
|
48
52
|
|
49
53
|
### Mocking for Test/Development
|
50
54
|
|
data/Rakefile
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
1
4
|
$LOAD_PATH.unshift 'lib'
|
2
5
|
|
3
6
|
task :default => :test
|
@@ -5,46 +8,6 @@ task :default => :test
|
|
5
8
|
desc "Run tests"
|
6
9
|
task :test do
|
7
10
|
Dir['test/*_test.rb'].each do |f|
|
8
|
-
require f
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
desc "Build a gem"
|
13
|
-
task :gem => [ :test, :gemspec, :build ]
|
14
|
-
|
15
|
-
begin
|
16
|
-
begin
|
17
|
-
require 'jeweler'
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler not available. Install it with: "
|
20
|
-
puts "gem install jeweler"
|
11
|
+
require File.expand_path(f)
|
21
12
|
end
|
22
|
-
|
23
|
-
require 'redis/feature_control'
|
24
|
-
|
25
|
-
Jeweler::Tasks.new do |gemspec|
|
26
|
-
gemspec.name = "redis_feature_control"
|
27
|
-
gemspec.summary = "Feature enable/disable library on top of Redis"
|
28
|
-
gemspec.description = gemspec.summary
|
29
|
-
gemspec.email = "bvandenbos@gmail.com"
|
30
|
-
gemspec.homepage = "http://github.com/bvandenbos/redis_feature_control"
|
31
|
-
gemspec.authors = ["Ben VandenBos"]
|
32
|
-
gemspec.version = Redis::FeatureControl::Version
|
33
|
-
|
34
|
-
gemspec.add_dependency "redis", ">= 0.1.1"
|
35
|
-
gemspec.add_dependency "redis-namespace", ">= 0.2.0"
|
36
|
-
gemspec.add_development_dependency "jeweler"
|
37
|
-
gemspec.add_development_dependency "mocha"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
desc "Push a new version to Gemcutter"
|
43
|
-
task :publish => [ :test, :gemspec, :build ] do
|
44
|
-
require 'redis/feature_control'
|
45
|
-
system "git tag v#{Redis::FeatureControl::Version}"
|
46
|
-
system "git push origin v#{Redis::FeatureControl::Version}"
|
47
|
-
system "git push origin master"
|
48
|
-
system "gem push pkg/redis_feature_control-#{Redis::FeatureControl::Version}.gem"
|
49
|
-
system "git clean -fd"
|
50
13
|
end
|
@@ -16,8 +16,6 @@ class Redis
|
|
16
16
|
|
17
17
|
module FeatureControl
|
18
18
|
|
19
|
-
Version = '0.0.1'
|
20
|
-
|
21
19
|
class Redis::FeatureControl::UnknownFeatureError < RuntimeError; end;
|
22
20
|
|
23
21
|
class << self
|
@@ -41,6 +39,11 @@ class Redis
|
|
41
39
|
@host, @port = value.split(":", 2)
|
42
40
|
redis_connect!
|
43
41
|
end
|
42
|
+
|
43
|
+
# Set the redis instance directly.
|
44
|
+
def connection=(redis)
|
45
|
+
@redis = redis
|
46
|
+
end
|
44
47
|
|
45
48
|
# Connects to redis on the current host/port and sets the redis object
|
46
49
|
def redis_connect!
|
@@ -3,115 +3,128 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
3
3
|
class Redis::FeatureControlTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
control.connection_string = 'localhost:9736'
|
7
|
+
control.unmock!
|
8
|
+
control.features = [:enabled_feature]
|
9
|
+
control.redis.flushall
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_connection_string_works
|
13
|
-
|
14
|
-
assert_equal('redis',
|
15
|
-
assert_equal('1234',
|
13
|
+
control.connection_string = "redis:1234"
|
14
|
+
assert_equal('redis', control.host)
|
15
|
+
assert_equal('1234', control.port)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_connection_works
|
19
|
+
redis = Redis.new(:host => 'localhost', :port => 9736, :thread_safe => true)
|
20
|
+
redis_namespace = Redis::Namespace.new(:feature_control_test, :redis => redis)
|
21
|
+
control.connection = redis_namespace
|
22
|
+
control.features = [:some_feature]
|
23
|
+
control.enable!(:some_feature)
|
24
|
+
assert redis.exists('feature_control_test:some_feature')
|
16
25
|
end
|
17
26
|
|
18
27
|
def test_redis
|
19
|
-
assert(
|
28
|
+
assert(control.redis.is_a?(Redis::Namespace))
|
20
29
|
end
|
21
30
|
|
22
31
|
def test_unknown_features_raise_errors
|
23
|
-
assert_raises(
|
24
|
-
|
32
|
+
assert_raises(control::UnknownFeatureError) do
|
33
|
+
control.enabled?(:some_feature)
|
25
34
|
end
|
26
35
|
end
|
27
36
|
|
28
37
|
def test_enable_disable
|
29
|
-
|
30
|
-
assert(
|
31
|
-
assert(!
|
38
|
+
control.features << :cool_service # add a feature
|
39
|
+
assert(control.enabled?(:cool_service)) # should be enabled by default
|
40
|
+
assert(!control.disabled?(:cool_service)) # should be enabled by default
|
32
41
|
|
33
|
-
|
34
|
-
assert(
|
42
|
+
control.enable!(:cool_service)
|
43
|
+
assert(control.enabled?(:cool_service)) # should still be enabled
|
35
44
|
|
36
|
-
|
37
|
-
assert(!
|
38
|
-
assert(
|
45
|
+
control.disable!(:cool_service)
|
46
|
+
assert(!control.enabled?(:cool_service)) # should still be enabled
|
47
|
+
assert(control.disabled?(:cool_service)) # should still be enabled
|
39
48
|
|
40
|
-
|
41
|
-
assert(
|
49
|
+
control.enable!(:cool_service)
|
50
|
+
assert(control.enabled?(:cool_service)) # should still be enabled
|
42
51
|
end
|
43
52
|
|
44
53
|
def test_set_status
|
54
|
+
control.features << :cool_service # add a feature
|
45
55
|
|
46
|
-
|
47
|
-
|
48
|
-
Redis::FeatureControl.set_status(:cool_service, 0.9) # <1
|
49
|
-
assert(Redis::FeatureControl.disabled?(:cool_service)) # should still be enabled
|
56
|
+
control.set_status(:cool_service, 0.9) # <1
|
57
|
+
assert(control.disabled?(:cool_service)) # should still be enabled
|
50
58
|
|
51
|
-
|
52
|
-
assert(
|
59
|
+
control.set_status(:cool_service, 1.0)
|
60
|
+
assert(control.enabled?(:cool_service)) # should still be enabled
|
53
61
|
|
54
|
-
|
55
|
-
assert(
|
62
|
+
control.set_status(:cool_service, -1)
|
63
|
+
assert(control.disabled?(:cool_service)) # should still be enabled
|
56
64
|
|
57
|
-
|
58
|
-
assert(
|
65
|
+
control.set_status(:cool_service, -1.0)
|
66
|
+
assert(control.disabled?(:cool_service)) # should still be enabled
|
59
67
|
|
60
|
-
|
61
|
-
assert(
|
62
|
-
|
63
|
-
Redis::FeatureControl.set_status(:cool_service, -42)
|
64
|
-
assert(Redis::FeatureControl.disabled?(:cool_service)) # should still be enabled
|
68
|
+
control.set_status(:cool_service, 42)
|
69
|
+
assert(control.enabled?(:cool_service)) # should still be enabled
|
65
70
|
|
71
|
+
control.set_status(:cool_service, -42)
|
72
|
+
assert(control.disabled?(:cool_service)) # should still be enabled
|
66
73
|
end
|
67
74
|
|
68
75
|
def test_state_string
|
69
|
-
|
76
|
+
control.features << :cool_service # add a feature
|
70
77
|
|
71
|
-
|
72
|
-
assert_equal('enabled',
|
78
|
+
control.enable!(:cool_service)
|
79
|
+
assert_equal('enabled', control.state(:cool_service))
|
73
80
|
|
74
|
-
|
75
|
-
assert_equal('disabled',
|
81
|
+
control.disable!(:cool_service)
|
82
|
+
assert_equal('disabled', control.state(:cool_service))
|
76
83
|
end
|
77
84
|
|
78
85
|
def test_check_feature
|
79
|
-
assert_raises(
|
80
|
-
|
86
|
+
assert_raises(control::UnknownFeatureError) do
|
87
|
+
control.enabled?(:some_feature)
|
81
88
|
end
|
82
89
|
|
83
90
|
assert_nothing_raised do
|
84
|
-
|
91
|
+
control.enabled?(:enabled_feature)
|
85
92
|
end
|
86
93
|
end
|
87
94
|
|
88
95
|
def test_mock
|
89
96
|
|
90
|
-
|
91
|
-
assert(
|
97
|
+
control.mock!
|
98
|
+
assert(control.mock?)
|
92
99
|
|
93
|
-
|
94
|
-
assert(!
|
100
|
+
control.unmock!
|
101
|
+
assert(!control.mock?)
|
95
102
|
end
|
96
103
|
|
97
104
|
def test_mock_enable_disable
|
98
|
-
|
105
|
+
control.mock!
|
99
106
|
|
100
|
-
|
107
|
+
control.expects(:redis).never # It's mocked, so it shouldn't use redis
|
101
108
|
|
102
|
-
|
103
|
-
assert(
|
104
|
-
assert(!
|
109
|
+
control.features << :cool_service # add a feature
|
110
|
+
assert(control.enabled?(:cool_service)) # should be enabled by default
|
111
|
+
assert(!control.disabled?(:cool_service)) # should be enabled by default
|
105
112
|
|
106
|
-
|
107
|
-
assert(
|
113
|
+
control.enable!(:cool_service)
|
114
|
+
assert(control.enabled?(:cool_service)) # should still be enabled
|
108
115
|
|
109
|
-
|
110
|
-
assert(!
|
111
|
-
assert(
|
116
|
+
control.disable!(:cool_service)
|
117
|
+
assert(!control.enabled?(:cool_service)) # should still be enabled
|
118
|
+
assert(control.disabled?(:cool_service)) # should still be enabled
|
112
119
|
|
113
|
-
|
114
|
-
assert(
|
120
|
+
control.enable!(:cool_service)
|
121
|
+
assert(control.enabled?(:cool_service)) # should still be enabled
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def control
|
127
|
+
Redis::FeatureControl
|
115
128
|
end
|
116
129
|
|
117
130
|
end
|
data/test/redis-test.conf
CHANGED
@@ -128,5 +128,5 @@ glueoutputbuf yes
|
|
128
128
|
# WARNING: object sharing is experimental, don't enable this feature
|
129
129
|
# in production before of Redis 1.0-stable. Still please try this feature in
|
130
130
|
# your development environment so that we can test it better.
|
131
|
-
shareobjects no
|
132
|
-
shareobjectspoolsize 1024
|
131
|
+
# shareobjects no
|
132
|
+
# shareobjectspoolsize 1024
|
data/test/test_helper.rb
CHANGED
@@ -26,7 +26,11 @@ end
|
|
26
26
|
at_exit do
|
27
27
|
next if $!
|
28
28
|
|
29
|
-
|
29
|
+
if defined?(MiniTest)
|
30
|
+
exit_code = MiniTest::Unit.new.run(ARGV)
|
31
|
+
else
|
32
|
+
exit_code = Test::Unit::AutoRunner.run
|
33
|
+
end
|
30
34
|
|
31
35
|
pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
|
32
36
|
puts "Killing test redis server..."
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_feature_control
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Ben VandenBos
|
@@ -9,64 +14,86 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2011-02-16 00:00:00 -08:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
|
-
name: redis
|
27
|
-
|
28
|
-
|
29
|
-
|
36
|
+
name: redis
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
30
40
|
requirements:
|
31
41
|
- - ">="
|
32
42
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 1
|
46
|
+
- 1
|
47
|
+
version: 0.1.1
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
35
50
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
37
|
-
|
38
|
-
|
39
|
-
|
51
|
+
name: redis-namespace
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
40
55
|
requirements:
|
41
56
|
- - ">="
|
42
57
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 2
|
61
|
+
- 0
|
62
|
+
version: 0.2.0
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
45
65
|
- !ruby/object:Gem::Dependency
|
46
66
|
name: mocha
|
47
|
-
|
48
|
-
|
49
|
-
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
50
70
|
requirements:
|
51
71
|
- - ">="
|
52
72
|
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
53
75
|
version: "0"
|
54
|
-
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
55
78
|
description: Feature enable/disable library on top of Redis
|
56
|
-
email:
|
79
|
+
email:
|
80
|
+
- bvandenbos@gmail.com
|
57
81
|
executables: []
|
58
82
|
|
59
83
|
extensions: []
|
60
84
|
|
61
|
-
extra_rdoc_files:
|
62
|
-
|
63
|
-
- README.md
|
85
|
+
extra_rdoc_files: []
|
86
|
+
|
64
87
|
files:
|
65
88
|
- .gitignore
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- HISTORY.md
|
66
92
|
- LICENSE
|
67
93
|
- README.md
|
68
94
|
- Rakefile
|
69
95
|
- lib/redis/feature_control.rb
|
96
|
+
- lib/redis/feature_control/version.rb
|
70
97
|
- test/feature_control_test.rb
|
71
98
|
- test/redis-test.conf
|
72
99
|
- test/test_helper.rb
|
@@ -75,29 +102,34 @@ homepage: http://github.com/bvandenbos/redis_feature_control
|
|
75
102
|
licenses: []
|
76
103
|
|
77
104
|
post_install_message:
|
78
|
-
rdoc_options:
|
79
|
-
|
105
|
+
rdoc_options: []
|
106
|
+
|
80
107
|
require_paths:
|
81
108
|
- lib
|
82
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
83
111
|
requirements:
|
84
112
|
- - ">="
|
85
113
|
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
86
116
|
version: "0"
|
87
|
-
version:
|
88
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
89
119
|
requirements:
|
90
120
|
- - ">="
|
91
121
|
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
|
122
|
+
segments:
|
123
|
+
- 1
|
124
|
+
- 3
|
125
|
+
- 6
|
126
|
+
version: 1.3.6
|
94
127
|
requirements: []
|
95
128
|
|
96
129
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.3.
|
130
|
+
rubygems_version: 1.3.7
|
98
131
|
signing_key:
|
99
132
|
specification_version: 3
|
100
133
|
summary: Feature enable/disable library on top of Redis
|
101
|
-
test_files:
|
102
|
-
|
103
|
-
- test/test_helper.rb
|
134
|
+
test_files: []
|
135
|
+
|