fflags 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -1
- data/lib/FFlags/version.rb +1 -1
- data/lib/fflags.rb +22 -3
- data/lib/fflags/api.rb +22 -7
- data/lib/fflags/redis_client.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72f65fe5ec5b36c7fff0bc23ea874aa82063ee4a
|
4
|
+
data.tar.gz: 64d8caa37df5953669231a67b126668627b9a154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85de7e1a2994de1979f2c66273e01b251b3f5ff0427de0564147f003be17d72297cdf06a661f7967873405d6228d4437f26b736b4ee81547898686480f84943e
|
7
|
+
data.tar.gz: cf5404220fb29854eef0fb2c02f2f99748554121aa57aef406f6e342e2fc2bc9841a6219c9f03026da5e719f20edcb649b7e893b6995c334858d5394c8ba764e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fflags (0.
|
4
|
+
fflags (0.3.0)
|
5
5
|
redis (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.3.0)
|
11
|
+
coderay (1.1.2)
|
11
12
|
diff-lcs (1.3)
|
13
|
+
method_source (0.9.0)
|
12
14
|
parallel (1.12.1)
|
13
15
|
parser (2.4.0.2)
|
14
16
|
ast (~> 2.3)
|
15
17
|
powerpack (0.1.1)
|
18
|
+
pry (0.11.3)
|
19
|
+
coderay (~> 1.1.0)
|
20
|
+
method_source (~> 0.9.0)
|
16
21
|
rainbow (3.0.0)
|
17
22
|
rake (10.5.0)
|
18
23
|
redis (4.0.1)
|
@@ -45,6 +50,7 @@ PLATFORMS
|
|
45
50
|
DEPENDENCIES
|
46
51
|
bundler (~> 1.16)
|
47
52
|
fflags!
|
53
|
+
pry
|
48
54
|
rake (~> 10.0)
|
49
55
|
rspec (~> 3.0)
|
50
56
|
rubocop
|
data/lib/FFlags/version.rb
CHANGED
data/lib/fflags.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'redis'
|
1
2
|
require 'fflags/version'
|
2
3
|
require 'fflags/configuration'
|
4
|
+
require 'fflags/redis_client'
|
3
5
|
require 'fflags/api'
|
4
6
|
|
5
7
|
# FFlags module
|
@@ -8,6 +10,7 @@ module FFlags
|
|
8
10
|
|
9
11
|
def config
|
10
12
|
yield configuration
|
13
|
+
api.reset
|
11
14
|
end
|
12
15
|
|
13
16
|
def flags
|
@@ -18,15 +21,15 @@ module FFlags
|
|
18
21
|
api.enabled?(flag_name)
|
19
22
|
end
|
20
23
|
|
21
|
-
def
|
24
|
+
def set(flag_name, bool)
|
22
25
|
api.set_flag(flag_name, bool)
|
23
26
|
end
|
24
27
|
|
25
|
-
def
|
28
|
+
def get(flag_name)
|
26
29
|
api.get_flag(flag_name)
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
32
|
+
def toggle(flag_name)
|
30
33
|
api.toggle_flag(flag_name)
|
31
34
|
end
|
32
35
|
|
@@ -34,6 +37,22 @@ module FFlags
|
|
34
37
|
api.reset
|
35
38
|
end
|
36
39
|
|
40
|
+
def method_missing(method_name, *args)
|
41
|
+
flag_name = method_name[0..-2]
|
42
|
+
|
43
|
+
if !method_name.to_s.end_with?('?') ||
|
44
|
+
!flags.include?(flag_name)
|
45
|
+
return super
|
46
|
+
end
|
47
|
+
|
48
|
+
api.get_flag(flag_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
def respond_to_missing?(method_name, include_private = false)
|
52
|
+
flag_name = method_name[0..-2]
|
53
|
+
method_name.to_s.end_with?('?') && flags.include?(flag_name) || super
|
54
|
+
end
|
55
|
+
|
37
56
|
def api
|
38
57
|
@api ||= Api.new
|
39
58
|
end
|
data/lib/fflags/api.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
require './lib/fflags/redis_client'
|
2
|
-
|
3
1
|
module FFlags
|
4
2
|
# Api Class
|
5
3
|
class Api
|
4
|
+
def initialize
|
5
|
+
load_flags
|
6
|
+
end
|
7
|
+
|
6
8
|
def flags
|
7
|
-
|
9
|
+
client.all(key)
|
8
10
|
end
|
9
11
|
|
10
12
|
def enabled?(flag_name)
|
@@ -16,9 +18,7 @@ module FFlags
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def get_flag(flag_name)
|
19
|
-
|
20
|
-
value = flags.dig(flag_name.to_sym) if value.nil?
|
21
|
-
truthy?(value)
|
21
|
+
truthy?(client.get(key, flag_name))
|
22
22
|
end
|
23
23
|
|
24
24
|
def toggle_flag(flag_name)
|
@@ -26,11 +26,22 @@ module FFlags
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def reset
|
29
|
-
client.reset(
|
29
|
+
client.reset(key)
|
30
|
+
load_flags
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_flags
|
34
|
+
default_flags.each do |flag, bool|
|
35
|
+
set_flag(flag, bool)
|
36
|
+
end
|
30
37
|
end
|
31
38
|
|
32
39
|
private
|
33
40
|
|
41
|
+
def question_mark_method?(method_name)
|
42
|
+
method_name[-1] == '?'
|
43
|
+
end
|
44
|
+
|
34
45
|
def truthy?(value)
|
35
46
|
value == true || value == 'true'
|
36
47
|
end
|
@@ -42,5 +53,9 @@ module FFlags
|
|
42
53
|
def client
|
43
54
|
RedisClient
|
44
55
|
end
|
56
|
+
|
57
|
+
def default_flags
|
58
|
+
FFlags.configuration.flags
|
59
|
+
end
|
45
60
|
end
|
46
61
|
end
|
data/lib/fflags/redis_client.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'redis'
|
2
|
-
|
3
1
|
module FFlags
|
4
2
|
# Redis Client
|
5
3
|
class RedisClient
|
@@ -8,6 +6,10 @@ module FFlags
|
|
8
6
|
client.hmset(key, field, value) == 'OK'
|
9
7
|
end
|
10
8
|
|
9
|
+
def all(key)
|
10
|
+
client.hgetall(key)
|
11
|
+
end
|
12
|
+
|
11
13
|
def get(key, field)
|
12
14
|
client.hget(key, field)
|
13
15
|
end
|