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 ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
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
@@ -0,0 +1,10 @@
1
+
2
+ ## 0.0.2 (2011-02-16)
3
+
4
+ * Switched to bundler
5
+ * Removed jeweler
6
+ * Added `connection=`
7
+
8
+ ## 0.0.1
9
+
10
+ * First version
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
- First configure it:
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.status(:cc_gateway) # => "disabled"
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.status(:cc_gateway) # => "enabled"
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!
@@ -0,0 +1,5 @@
1
+ class Redis
2
+ module FeatureControl
3
+ Version = '0.0.2'
4
+ end
5
+ end
@@ -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
- Redis::FeatureControl.connection_string = 'localhost:9736'
7
- Redis::FeatureControl.unmock!
8
- Redis::FeatureControl.features = [:enabled_feature]
9
- Redis::FeatureControl.redis.flushall
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
- Redis::FeatureControl.connection_string = "redis:1234"
14
- assert_equal('redis', Redis::FeatureControl.host)
15
- assert_equal('1234', Redis::FeatureControl.port)
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(Redis::FeatureControl.redis.is_a?(Redis::Namespace))
28
+ assert(control.redis.is_a?(Redis::Namespace))
20
29
  end
21
30
 
22
31
  def test_unknown_features_raise_errors
23
- assert_raises(Redis::FeatureControl::UnknownFeatureError) do
24
- Redis::FeatureControl.enabled?(:some_feature)
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
- Redis::FeatureControl.features << :cool_service # add a feature
30
- assert(Redis::FeatureControl.enabled?(:cool_service)) # should be enabled by default
31
- assert(!Redis::FeatureControl.disabled?(:cool_service)) # should be enabled by default
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
- Redis::FeatureControl.enable!(:cool_service)
34
- assert(Redis::FeatureControl.enabled?(:cool_service)) # should still be enabled
42
+ control.enable!(:cool_service)
43
+ assert(control.enabled?(:cool_service)) # should still be enabled
35
44
 
36
- Redis::FeatureControl.disable!(:cool_service)
37
- assert(!Redis::FeatureControl.enabled?(:cool_service)) # should still be enabled
38
- assert(Redis::FeatureControl.disabled?(:cool_service)) # should still be enabled
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
- Redis::FeatureControl.enable!(:cool_service)
41
- assert(Redis::FeatureControl.enabled?(:cool_service)) # should still be enabled
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
- Redis::FeatureControl.features << :cool_service # add a feature
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
- Redis::FeatureControl.set_status(:cool_service, 1.0)
52
- assert(Redis::FeatureControl.enabled?(:cool_service)) # should still be enabled
59
+ control.set_status(:cool_service, 1.0)
60
+ assert(control.enabled?(:cool_service)) # should still be enabled
53
61
 
54
- Redis::FeatureControl.set_status(:cool_service, -1)
55
- assert(Redis::FeatureControl.disabled?(:cool_service)) # should still be enabled
62
+ control.set_status(:cool_service, -1)
63
+ assert(control.disabled?(:cool_service)) # should still be enabled
56
64
 
57
- Redis::FeatureControl.set_status(:cool_service, -1.0)
58
- assert(Redis::FeatureControl.disabled?(:cool_service)) # should still be enabled
65
+ control.set_status(:cool_service, -1.0)
66
+ assert(control.disabled?(:cool_service)) # should still be enabled
59
67
 
60
- Redis::FeatureControl.set_status(:cool_service, 42)
61
- assert(Redis::FeatureControl.enabled?(:cool_service)) # should still be enabled
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
- Redis::FeatureControl.features << :cool_service # add a feature
76
+ control.features << :cool_service # add a feature
70
77
 
71
- Redis::FeatureControl.enable!(:cool_service)
72
- assert_equal('enabled', Redis::FeatureControl.state(:cool_service))
78
+ control.enable!(:cool_service)
79
+ assert_equal('enabled', control.state(:cool_service))
73
80
 
74
- Redis::FeatureControl.disable!(:cool_service)
75
- assert_equal('disabled', Redis::FeatureControl.state(:cool_service))
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(Redis::FeatureControl::UnknownFeatureError) do
80
- Redis::FeatureControl.enabled?(:some_feature)
86
+ assert_raises(control::UnknownFeatureError) do
87
+ control.enabled?(:some_feature)
81
88
  end
82
89
 
83
90
  assert_nothing_raised do
84
- Redis::FeatureControl.enabled?(:enabled_feature)
91
+ control.enabled?(:enabled_feature)
85
92
  end
86
93
  end
87
94
 
88
95
  def test_mock
89
96
 
90
- Redis::FeatureControl.mock!
91
- assert(Redis::FeatureControl.mock?)
97
+ control.mock!
98
+ assert(control.mock?)
92
99
 
93
- Redis::FeatureControl.unmock!
94
- assert(!Redis::FeatureControl.mock?)
100
+ control.unmock!
101
+ assert(!control.mock?)
95
102
  end
96
103
 
97
104
  def test_mock_enable_disable
98
- Redis::FeatureControl.mock!
105
+ control.mock!
99
106
 
100
- Redis::FeatureControl.expects(:redis).never # It's mocked, so it shouldn't use redis
107
+ control.expects(:redis).never # It's mocked, so it shouldn't use redis
101
108
 
102
- Redis::FeatureControl.features << :cool_service # add a feature
103
- assert(Redis::FeatureControl.enabled?(:cool_service)) # should be enabled by default
104
- assert(!Redis::FeatureControl.disabled?(:cool_service)) # should be enabled by default
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
- Redis::FeatureControl.enable!(:cool_service)
107
- assert(Redis::FeatureControl.enabled?(:cool_service)) # should still be enabled
113
+ control.enable!(:cool_service)
114
+ assert(control.enabled?(:cool_service)) # should still be enabled
108
115
 
109
- Redis::FeatureControl.disable!(:cool_service)
110
- assert(!Redis::FeatureControl.enabled?(:cool_service)) # should still be enabled
111
- assert(Redis::FeatureControl.disabled?(:cool_service)) # should still be enabled
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
- Redis::FeatureControl.enable!(:cool_service)
114
- assert(Redis::FeatureControl.enabled?(:cool_service)) # should still be enabled
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
- exit_code = Test::Unit::AutoRunner.run
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
- version: 0.0.1
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: 2010-03-10 00:00:00 -08:00
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: redis
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
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
- version: 0.1.1
24
- version:
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-namespace
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
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
- version: 0.2.0
34
- version:
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: jeweler
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
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
- version: "0"
44
- version:
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
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
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
- version:
76
+ type: :development
77
+ version_requirements: *id004
55
78
  description: Feature enable/disable library on top of Redis
56
- email: bvandenbos@gmail.com
79
+ email:
80
+ - bvandenbos@gmail.com
57
81
  executables: []
58
82
 
59
83
  extensions: []
60
84
 
61
- extra_rdoc_files:
62
- - LICENSE
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
- - --charset=UTF-8
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
- version: "0"
93
- version:
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.5
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
- - test/feature_control_test.rb
103
- - test/test_helper.rb
134
+ test_files: []
135
+