feature_creep 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/feature_creep.rb +8 -0
- data/lib/feature_creep/redis_datastore.rb +28 -33
- data/lib/feature_creep/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/lib/feature_creep.rb
CHANGED
@@ -23,18 +23,22 @@ class FeatureCreep
|
|
23
23
|
|
24
24
|
# Activate Methods
|
25
25
|
def activate_globally(feature)
|
26
|
+
add_feature(feature)
|
26
27
|
@datastore.activate_globally(feature)
|
27
28
|
end
|
28
29
|
|
29
30
|
def activate_scope(feature, scope)
|
31
|
+
add_feature(feature)
|
30
32
|
@datastore.activate_scope(feature, scope)
|
31
33
|
end
|
32
34
|
|
33
35
|
def activate_agent_id(feature, agent_id)
|
36
|
+
add_feature(feature)
|
34
37
|
@datastore.activate_agent_id(feature, agent_id)
|
35
38
|
end
|
36
39
|
|
37
40
|
def activate_percentage(feature, percentage)
|
41
|
+
add_feature(feature)
|
38
42
|
@datastore.activate_percentage(feature, percentage)
|
39
43
|
end
|
40
44
|
|
@@ -108,6 +112,10 @@ class FeatureCreep
|
|
108
112
|
@datastore.add_feature(feature)
|
109
113
|
end
|
110
114
|
|
115
|
+
def remove_feature(feature)
|
116
|
+
@datastore.remove_feature(feature)
|
117
|
+
end
|
118
|
+
|
111
119
|
def info(feature = nil)
|
112
120
|
@info.call(self,feature)
|
113
121
|
end
|
@@ -6,57 +6,50 @@ class FeatureCreep
|
|
6
6
|
@redis = datastore || Redis.new
|
7
7
|
end
|
8
8
|
|
9
|
+
# Activate Methods
|
9
10
|
def activate_globally(feature)
|
10
|
-
add_feature(feature)
|
11
11
|
@redis.sadd(global_key, feature)
|
12
12
|
end
|
13
13
|
|
14
|
-
def deactivate_globally(feature)
|
15
|
-
@redis.srem(global_key, feature)
|
16
|
-
end
|
17
|
-
|
18
14
|
def activate_scope(feature, scope)
|
19
|
-
add_feature(feature)
|
20
15
|
@redis.sadd(scope_key(feature), scope)
|
21
16
|
end
|
22
17
|
|
23
|
-
def
|
24
|
-
@redis.
|
18
|
+
def activate_agent_id(feature, agent_id)
|
19
|
+
@redis.sadd(agent_id_key(feature), agent_id)
|
25
20
|
end
|
26
21
|
|
27
|
-
def
|
28
|
-
@redis.
|
29
|
-
@redis.del(agent_id_key(feature))
|
30
|
-
@redis.del(percentage_key(feature))
|
31
|
-
deactivate_globally(feature)
|
22
|
+
def activate_percentage(feature, percentage)
|
23
|
+
@redis.set(percentage_key(feature), percentage)
|
32
24
|
end
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
@redis.
|
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)
|
37
33
|
end
|
38
34
|
|
39
35
|
def deactivate_agent_id(feature, agent_id)
|
40
36
|
@redis.srem(agent_id_key(feature), agent_id)
|
41
37
|
end
|
42
38
|
|
43
|
-
def
|
44
|
-
|
45
|
-
active_globally?(feature) ||
|
46
|
-
agent_id_in_active_scope?(feature, agent_id) ||
|
47
|
-
agent_id_active?(feature, agent_id) ||
|
48
|
-
agent_id_within_active_percentage?(feature, agent_id)
|
49
|
-
else
|
50
|
-
active_globally?(feature)
|
51
|
-
end
|
39
|
+
def deactivate_percentage(feature)
|
40
|
+
@redis.del(percentage_key(feature))
|
52
41
|
end
|
53
42
|
|
54
|
-
def
|
55
|
-
@redis.
|
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)
|
56
48
|
end
|
57
49
|
|
58
|
-
|
59
|
-
|
50
|
+
# Reporting Methods
|
51
|
+
def active_global_features
|
52
|
+
(@redis.smembers(global_key) || []).map(&:to_sym)
|
60
53
|
end
|
61
54
|
|
62
55
|
def active_scopes(feature)
|
@@ -67,14 +60,11 @@ class FeatureCreep
|
|
67
60
|
@redis.smembers(agent_id_key(feature))
|
68
61
|
end
|
69
62
|
|
70
|
-
def active_global_features
|
71
|
-
(@redis.smembers(global_key) || []).map(&:to_sym)
|
72
|
-
end
|
73
|
-
|
74
63
|
def active_percentage(feature)
|
75
64
|
@redis.get(percentage_key(feature))
|
76
65
|
end
|
77
66
|
|
67
|
+
# Boolean Methods
|
78
68
|
def active_globally?(feature)
|
79
69
|
@redis.sismember(global_key, feature)
|
80
70
|
end
|
@@ -89,6 +79,7 @@ class FeatureCreep
|
|
89
79
|
agent_id % 100 < percentage.to_i
|
90
80
|
end
|
91
81
|
|
82
|
+
# Utility Methods
|
92
83
|
def features
|
93
84
|
@redis.smembers(@key_prefix).map(&:to_sym)
|
94
85
|
end
|
@@ -97,6 +88,10 @@ class FeatureCreep
|
|
97
88
|
@redis.sadd(@key_prefix, feature)
|
98
89
|
end
|
99
90
|
|
91
|
+
def remove_feature(feature)
|
92
|
+
@redis.srem(@key_prefix, feature)
|
93
|
+
end
|
94
|
+
|
100
95
|
private
|
101
96
|
def key(name)
|
102
97
|
"#{@key_prefix}:#{name}"
|