flag 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/SPEC.md +2 -2
- data/flag.gemspec +2 -2
- data/lib/flag.rb +16 -22
- data/test/flag_test.rb +7 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d92ca5beee75e55334375129bf62b0836adf5f7
|
4
|
+
data.tar.gz: 868a270b5142903ef440f22fd6385a380fcc4bf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8f3b6480ce579aa163eea68559385b6790bd02072fc08089a8bc26d6aca6e18b6e45a53920c7a6ad3cd45353b5a6cd5b353d1a0cb8a0508d730faa8b0a49020
|
7
|
+
data.tar.gz: 7b064e5d80901a1b77d80b50f74cea3c91a681b089d570f596d9d958bc7016be866d6e7bba33d22587b1616d1746546d33aa2cd5adaad3208cc679ea9f993a41
|
data/README.md
CHANGED
@@ -26,6 +26,17 @@ else
|
|
26
26
|
end
|
27
27
|
```
|
28
28
|
|
29
|
+
If you enable (`on!`) with `Integer`, `Fixnum` or `String` they will be treated
|
30
|
+
as ids of your application, in the other hand if you use `Symbol` it will be
|
31
|
+
treated as a `Group`.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Flag(:something).on!(1)
|
35
|
+
Flag(:something).on!("uuid")
|
36
|
+
|
37
|
+
Flag(:something).on!(:group)
|
38
|
+
```
|
39
|
+
|
29
40
|
## Enable/Check feature flags
|
30
41
|
|
31
42
|
### Ids
|
data/SPEC.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
```ruby
|
2
2
|
if Flag(:experiment).on?
|
3
3
|
end
|
4
4
|
|
@@ -12,5 +12,5 @@ Flag(:experiment).on!(:group)
|
|
12
12
|
Flag(:experiment).on?(user.id)
|
13
13
|
Flag(:experiment).on?(:group)
|
14
14
|
|
15
|
-
Flag.group[:group] = lambda { |id| id % 2 }
|
15
|
+
Flag.group[:group] = lambda { |id| id % 2 == 0 }
|
16
16
|
```
|
data/flag.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "flag"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.2"
|
4
4
|
s.summary = "Simple feature flags"
|
5
5
|
s.description = "Feature flags for the humans and the coders"
|
6
6
|
s.authors = ["elcuervo"]
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.files = `git ls-files`.split("\n")
|
11
11
|
s.test_files = `git ls-files test`.split("\n")
|
12
12
|
|
13
|
-
s.add_dependency("redic", "~>
|
13
|
+
s.add_dependency("redic", "~> 1.4.1")
|
14
14
|
|
15
15
|
s.add_development_dependency("minitest", "~> 5.3.0")
|
16
16
|
s.add_development_dependency("minitest-given", "~> 3.0.0")
|
data/lib/flag.rb
CHANGED
@@ -20,15 +20,15 @@ module Flag
|
|
20
20
|
"#{Flag::FEATURES}:#{name}"
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
{ percentage: percentage
|
23
|
+
def activated
|
24
|
+
{ percentage: percentage, users: users, groups: groups }
|
25
25
|
end
|
26
26
|
|
27
27
|
def groups; members_for(GROUPS).map(&:to_sym) end
|
28
28
|
def users; members_for(USERS) end
|
29
29
|
|
30
30
|
def include?(item)
|
31
|
-
return percentage == item
|
31
|
+
return percentage == item.to_i if item.to_s.end_with?("%")
|
32
32
|
return true if Zlib.crc32(item.to_s) % 100 < percentage
|
33
33
|
|
34
34
|
Flag.store.call("SISMEMBER", subkey(item), item).to_i == 1
|
@@ -38,16 +38,16 @@ module Flag
|
|
38
38
|
[USERS, GROUPS].each { |k| Flag.store.call("DEL", "#{key}:#{k}") }
|
39
39
|
end
|
40
40
|
|
41
|
+
def percentage
|
42
|
+
Flag.store.call("HGET", Flag::FEATURES, name).to_i
|
43
|
+
end
|
44
|
+
|
41
45
|
private
|
42
46
|
|
43
47
|
def members_for(type)
|
44
48
|
Flag.store.call("SMEMBERS", "#{key}:#{type}") || []
|
45
49
|
end
|
46
50
|
|
47
|
-
def percentage
|
48
|
-
Flag.store.call("HGET", Flag::FEATURES, name).to_i
|
49
|
-
end
|
50
|
-
|
51
51
|
def subkey(item)
|
52
52
|
"#{key}:#{subgroup(item)}"
|
53
53
|
end
|
@@ -69,9 +69,9 @@ module Flag
|
|
69
69
|
@members = Members.new(name)
|
70
70
|
end
|
71
71
|
|
72
|
-
def reset;
|
73
|
-
def key;
|
74
|
-
def
|
72
|
+
def reset; @members.reset end
|
73
|
+
def key; @members.key end
|
74
|
+
def activated; @members.activated end
|
75
75
|
|
76
76
|
def off?; !active? end
|
77
77
|
|
@@ -88,21 +88,17 @@ module Flag
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def off!
|
91
|
-
|
91
|
+
@members << "0%"
|
92
92
|
end
|
93
93
|
|
94
|
-
def on!(what =
|
95
|
-
|
96
|
-
@members << what
|
97
|
-
else
|
98
|
-
Flag.store.call("HSET", Flag::FEATURES, name, 100)
|
99
|
-
end
|
94
|
+
def on!(what = "100%")
|
95
|
+
@members << what
|
100
96
|
end
|
101
97
|
|
102
98
|
private
|
103
99
|
|
104
100
|
def active?
|
105
|
-
|
101
|
+
@members.percentage == 100
|
106
102
|
end
|
107
103
|
end
|
108
104
|
|
@@ -116,7 +112,7 @@ module Flag
|
|
116
112
|
end
|
117
113
|
|
118
114
|
def enabled
|
119
|
-
features.select { |k, v|
|
115
|
+
features.select { |k, v| v.on? }.keys
|
120
116
|
end
|
121
117
|
|
122
118
|
def store; @store ||= Redic.new end
|
@@ -127,9 +123,7 @@ module Flag
|
|
127
123
|
def features
|
128
124
|
@_features ||= Hash.new { |h, k| h[k] = Feature.new(k) }
|
129
125
|
|
130
|
-
self.store.call("
|
131
|
-
@_features[slice.first.to_sym]
|
132
|
-
end
|
126
|
+
self.store.call("HKEYS", FEATURES).each { |k| @_features[k.to_sym] }
|
133
127
|
|
134
128
|
@_features
|
135
129
|
end
|
data/test/flag_test.rb
CHANGED
@@ -36,7 +36,7 @@ describe Flag do
|
|
36
36
|
Then { groups == [:staff] }
|
37
37
|
end
|
38
38
|
|
39
|
-
context "testing if feature is
|
39
|
+
context "testing if feature is activated for a group" do
|
40
40
|
Given { Flag(:test).on!(:staff) }
|
41
41
|
When(:feature) { Flag(:test).on?(:staff) }
|
42
42
|
Then { feature == true }
|
@@ -91,9 +91,11 @@ describe Flag do
|
|
91
91
|
Given { Flag(:test).on!("UUID") }
|
92
92
|
Given { Flag(:test).on!(:staff) }
|
93
93
|
|
94
|
-
Then { Flag(:test).
|
95
|
-
And { Flag(:test).
|
96
|
-
And { Flag(:test).
|
97
|
-
And { Flag(:test).
|
94
|
+
Then { Flag(:test).activated.is_a?(Hash) }
|
95
|
+
And { Flag(:test).activated[:percentage] == 50 }
|
96
|
+
And { Flag(:test).activated[:users].size == 2 }
|
97
|
+
And { Flag(:test).activated[:users].include?("25") }
|
98
|
+
And { Flag(:test).activated[:users].include?("UUID") }
|
99
|
+
And { Flag(:test).activated[:groups] == [:staff] }
|
98
100
|
end
|
99
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- elcuervo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redic
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.4.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.4.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|