feature_creep-redis 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/Gemfile +3 -0
- data/README.md +4 -0
- data/feature_creep-redis.gemspec +32 -0
- data/lib/feature_creep.rb +1 -0
- data/lib/feature_creep/redis_data_store.rb +116 -0
- data/lib/feature_creep/version.rb +5 -0
- metadata +164 -0
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
19
|
+
|
20
|
+
*~
|
21
|
+
\#*
|
22
|
+
.\#*
|
23
|
+
|
24
|
+
.DS_Store
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "feature_creep/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "feature_creep-redis"
|
7
|
+
s.version = FeatureCreep::RedisDataStore::VERSION
|
8
|
+
s.authors = ["Christian Trosclair"]
|
9
|
+
s.email = ["xn@hybridgroup.com"]
|
10
|
+
s.description = "redis datastore for feature_creep gem"
|
11
|
+
s.summary = "redis datastore for feature_creep gem"
|
12
|
+
s.homepage = "https://github.com/hybridgroup/feature_creep"
|
13
|
+
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
|
16
|
+
s.rubyforge_project = "feature_creep-redis"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
# specify any dependencies here; for example:
|
24
|
+
s.add_development_dependency "rspec", "~> 2.10.0"
|
25
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
26
|
+
s.add_development_dependency "jeweler", "~> 1.6.4"
|
27
|
+
s.add_development_dependency "bourne", "1.0"
|
28
|
+
s.add_development_dependency "mocha", "0.9.8"
|
29
|
+
s.add_development_dependency "pry", "0.9.10"
|
30
|
+
|
31
|
+
s.add_runtime_dependency "redis"
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'feature_creep/redis_data_store'
|
@@ -0,0 +1,116 @@
|
|
1
|
+
class FeatureCreep
|
2
|
+
class RedisDataStore
|
3
|
+
|
4
|
+
def initialize(datastore = nil, key_prefix = "feature_creep")
|
5
|
+
@key_prefix = key_prefix
|
6
|
+
@redis = datastore || Redis.new
|
7
|
+
end
|
8
|
+
|
9
|
+
# Activate Methods
|
10
|
+
def activate_globally(feature)
|
11
|
+
@redis.sadd(global_key, feature)
|
12
|
+
end
|
13
|
+
|
14
|
+
def activate_scope(feature, scope)
|
15
|
+
@redis.sadd(scope_key(feature), scope)
|
16
|
+
end
|
17
|
+
|
18
|
+
def activate_agent_id(feature, agent_id)
|
19
|
+
@redis.sadd(agent_id_key(feature), agent_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def activate_percentage(feature, percentage)
|
23
|
+
@redis.set(percentage_key(feature), percentage)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Deactivate Methods
|
27
|
+
def deactivate_globally(feature)
|
28
|
+
@redis.srem(global_key, feature)
|
29
|
+
end
|
30
|
+
|
31
|
+
def deactivate_scope(feature, scope)
|
32
|
+
@redis.srem(scope_key(feature), scope)
|
33
|
+
end
|
34
|
+
|
35
|
+
def deactivate_agent_id(feature, agent_id)
|
36
|
+
@redis.srem(agent_id_key(feature), agent_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def deactivate_percentage(feature)
|
40
|
+
@redis.del(percentage_key(feature))
|
41
|
+
end
|
42
|
+
|
43
|
+
def deactivate_all(feature)
|
44
|
+
@redis.del(scope_key(feature))
|
45
|
+
@redis.del(agent_id_key(feature))
|
46
|
+
@redis.del(percentage_key(feature))
|
47
|
+
deactivate_globally(feature)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Reporting Methods
|
51
|
+
def active_global_features
|
52
|
+
(@redis.smembers(global_key) || []).map(&:to_sym)
|
53
|
+
end
|
54
|
+
|
55
|
+
def active_scopes(feature)
|
56
|
+
@redis.smembers(scope_key(feature)) || []
|
57
|
+
end
|
58
|
+
|
59
|
+
def active_agent_ids(feature)
|
60
|
+
@redis.smembers(agent_id_key(feature))
|
61
|
+
end
|
62
|
+
|
63
|
+
def active_percentage(feature)
|
64
|
+
@redis.get(percentage_key(feature))
|
65
|
+
end
|
66
|
+
|
67
|
+
# Boolean Methods
|
68
|
+
def active_globally?(feature)
|
69
|
+
@redis.sismember(global_key, feature)
|
70
|
+
end
|
71
|
+
|
72
|
+
def agent_id_active?(feature, agent_id)
|
73
|
+
@redis.sismember(agent_id_key(feature), agent_id)
|
74
|
+
end
|
75
|
+
|
76
|
+
def agent_id_within_active_percentage?(feature, agent_id)
|
77
|
+
percentage = active_percentage(feature)
|
78
|
+
return false if percentage.nil?
|
79
|
+
agent_id % 100 < percentage.to_i
|
80
|
+
end
|
81
|
+
|
82
|
+
# Utility Methods
|
83
|
+
def features
|
84
|
+
@redis.smembers(@key_prefix).map(&:to_sym)
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_feature(feature)
|
88
|
+
@redis.sadd(@key_prefix, feature)
|
89
|
+
end
|
90
|
+
|
91
|
+
def remove_feature(feature)
|
92
|
+
@redis.srem(@key_prefix, feature)
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
def key(name)
|
97
|
+
"#{@key_prefix}:#{name}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def scope_key(name)
|
101
|
+
"#{key(name)}:scopes"
|
102
|
+
end
|
103
|
+
|
104
|
+
def agent_id_key(name)
|
105
|
+
"#{key(name)}:agent_ids"
|
106
|
+
end
|
107
|
+
|
108
|
+
def percentage_key(name)
|
109
|
+
"#{key(name)}:percentage"
|
110
|
+
end
|
111
|
+
|
112
|
+
def global_key
|
113
|
+
"#{@key_prefix}:__global__"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feature_creep-redis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christian Trosclair
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.10.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.10.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: jeweler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.6.4
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.4
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bourne
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mocha
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.9.8
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - '='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.9.8
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pry
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - '='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.9.10
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - '='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.9.10
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: redis
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: redis datastore for feature_creep gem
|
127
|
+
email:
|
128
|
+
- xn@hybridgroup.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- Gemfile
|
135
|
+
- README.md
|
136
|
+
- feature_creep-redis.gemspec
|
137
|
+
- lib/feature_creep.rb
|
138
|
+
- lib/feature_creep/redis_data_store.rb
|
139
|
+
- lib/feature_creep/version.rb
|
140
|
+
homepage: https://github.com/hybridgroup/feature_creep
|
141
|
+
licenses: []
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project: feature_creep-redis
|
160
|
+
rubygems_version: 1.8.24
|
161
|
+
signing_key:
|
162
|
+
specification_version: 3
|
163
|
+
summary: redis datastore for feature_creep gem
|
164
|
+
test_files: []
|