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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa905390895050cd8a589c4c97f36cc1b3d8a8b9
4
- data.tar.gz: 360389f7f12e04b64b009bc4ba63cad0b0d40481
3
+ metadata.gz: 6d92ca5beee75e55334375129bf62b0836adf5f7
4
+ data.tar.gz: 868a270b5142903ef440f22fd6385a380fcc4bf3
5
5
  SHA512:
6
- metadata.gz: 839277859db6982e7fb3833642a79ff49f83c0764a50390021648b6319bea6746fd60bed4b965d55450fdceee9a481075bac5f6f35588fecb937430a860a3d1a
7
- data.tar.gz: 16fdbe22d8fa51324ec895b2db0d20cf83e2ea12395b91cb782b34e4ce11fd89a42aea67ee18ba49e1bd28a92006a938ceff14a47f0232976acfe41dba87ee90
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
- ``ruby
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.1"
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", "~> 0.0.8")
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 actived
24
- { percentage: percentage.to_i, users: users, groups: groups }
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[0...-1].to_i if item.to_s.end_with?("%")
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; @members.reset end
73
- def key; @members.key end
74
- def actived; @members.actived end
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
- Flag.store.call("HSET", Flag::FEATURES, name, 0)
91
+ @members << "0%"
92
92
  end
93
93
 
94
- def on!(what = false)
95
- if what
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
- Flag.store.call("HGET", FEATURES, name).to_i == 100
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| k if v.on? }.keys
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("HGETALL", FEATURES).each_slice(2) do |slice|
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 actived for a group" do
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).actived.is_a?(Hash) }
95
- And { Flag(:test).actived[:percentage] == 50 }
96
- And { Flag(:test).actived[:users] == ["25", "UUID"] }
97
- And { Flag(:test).actived[:groups] == [:staff] }
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.1
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: 2014-04-23 00:00:00.000000000 Z
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: 0.0.8
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: 0.0.8
26
+ version: 1.4.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement