unveil-ruby 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/unveil/app.rb +49 -0
- data/lib/unveil/feature.rb +18 -10
- data/lib/unveil/version.rb +1 -1
- data/lib/unveil.rb +21 -0
- metadata +1 -1
data/README.md
CHANGED
data/lib/unveil/app.rb
CHANGED
@@ -5,6 +5,38 @@ module Unveil
|
|
5
5
|
@attributes ||= JSON.parse(Unveil.get("").body)
|
6
6
|
end
|
7
7
|
|
8
|
+
def feature_names(reload = false)
|
9
|
+
features(reload).collect(&:name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def features(reload = false)
|
13
|
+
@features = nil if reload
|
14
|
+
|
15
|
+
unless @features
|
16
|
+
@features = attributes(reload)['features']
|
17
|
+
|
18
|
+
if Unveil.scan_for_features?
|
19
|
+
implemented_features.each do |name, paths|
|
20
|
+
if @features.collect { |f| f['name'] }.include?(name)
|
21
|
+
feature = @features.detect { |f| f['name'] == name }
|
22
|
+
feature['paths'] = paths
|
23
|
+
else
|
24
|
+
implemented_feature = {
|
25
|
+
'name' => name,
|
26
|
+
'groups' => [],
|
27
|
+
'percentage' => nil,
|
28
|
+
'user_count' => 0,
|
29
|
+
'paths' => paths
|
30
|
+
}
|
31
|
+
@features << implemented_feature
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
@features.collect { |f| Unveil::Feature.new(f) }.sort_by(&:name)
|
38
|
+
end
|
39
|
+
|
8
40
|
def method_missing(method, *args, &block)
|
9
41
|
if attributes.has_key?(method.to_s)
|
10
42
|
attributes(*args)[method.to_s]
|
@@ -12,5 +44,22 @@ module Unveil
|
|
12
44
|
super
|
13
45
|
end
|
14
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def implemented_features
|
51
|
+
@implemented_features ||= Dir[*Unveil.scan_dirs].inject({}) do |obj, path|
|
52
|
+
File.open(path) do |f|
|
53
|
+
f.grep(/rollout\?/) do |line|
|
54
|
+
line.scan(/rollout\?\s*\(*:(\w+)/).each do |line|
|
55
|
+
obj[line[0]] ||= []
|
56
|
+
obj[line[0]] << path
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
obj
|
62
|
+
end
|
63
|
+
end
|
15
64
|
end
|
16
65
|
end
|
data/lib/unveil/feature.rb
CHANGED
@@ -1,41 +1,49 @@
|
|
1
1
|
module Unveil
|
2
2
|
class Feature
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(attrs)
|
4
|
+
@attributes = attrs
|
5
5
|
end
|
6
6
|
|
7
7
|
def enabled(user_id)
|
8
|
-
Unveil.get "features/#{
|
8
|
+
Unveil.get "features/#{name}/enabled/#{user_id}"
|
9
9
|
end
|
10
10
|
|
11
11
|
def deactivate_all
|
12
|
-
Unveil.post 'features/deactivate_all', feature:
|
12
|
+
Unveil.post 'features/deactivate_all', feature: name
|
13
13
|
end
|
14
14
|
|
15
15
|
def activate_group(group)
|
16
16
|
group = group.is_a?(Unveil::Group) ? group.name : group
|
17
|
-
Unveil.post 'features/activate_group', feature:
|
17
|
+
Unveil.post 'features/activate_group', feature: name, group: group
|
18
18
|
end
|
19
19
|
|
20
20
|
def deactivate_group(group)
|
21
21
|
group = group.is_a?(Unveil::Group) ? group.name : group
|
22
|
-
Unveil.post 'features/deactivate_group', feature:
|
22
|
+
Unveil.post 'features/deactivate_group', feature: name, group: group
|
23
23
|
end
|
24
24
|
|
25
25
|
def activate_user(user_id)
|
26
|
-
Unveil.post 'features/activate_user', feature:
|
26
|
+
Unveil.post 'features/activate_user', feature: name, user_id: user_id
|
27
27
|
end
|
28
28
|
|
29
29
|
def deactivate_user(user_id)
|
30
|
-
Unveil.post 'features/deactivate_user', feature:
|
30
|
+
Unveil.post 'features/deactivate_user', feature: name, user_id: user_id
|
31
31
|
end
|
32
32
|
|
33
33
|
def activate_percentage(percentage)
|
34
|
-
Unveil.post 'features/activate_percentage', feature:
|
34
|
+
Unveil.post 'features/activate_percentage', feature: name, percentage: percentage
|
35
35
|
end
|
36
36
|
|
37
37
|
def deactivate_percentage
|
38
|
-
Unveil.post 'features/deactivate_percentage', feature:
|
38
|
+
Unveil.post 'features/deactivate_percentage', feature: name
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(method, *args, &block)
|
42
|
+
if @attributes.has_key?(method.to_s)
|
43
|
+
@attributes[method.to_s]
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
end
|
data/lib/unveil/version.rb
CHANGED
data/lib/unveil.rb
CHANGED
@@ -2,6 +2,11 @@ require 'unveil/version'
|
|
2
2
|
require 'net/https'
|
3
3
|
|
4
4
|
module Unveil
|
5
|
+
@@public_key = nil
|
6
|
+
@@private_key = nil
|
7
|
+
@@scan_for_features = false
|
8
|
+
@@scan_dirs = []
|
9
|
+
|
5
10
|
class << self
|
6
11
|
def configure
|
7
12
|
yield self
|
@@ -15,6 +20,22 @@ module Unveil
|
|
15
20
|
@@private_key = private_key
|
16
21
|
end
|
17
22
|
|
23
|
+
def scan_for_features=(bool)
|
24
|
+
@@scan_for_features = bool
|
25
|
+
end
|
26
|
+
|
27
|
+
def scan_for_features?
|
28
|
+
@@scan_for_features
|
29
|
+
end
|
30
|
+
|
31
|
+
def scan_dirs=(dirs)
|
32
|
+
@@scan_dirs = dirs
|
33
|
+
end
|
34
|
+
|
35
|
+
def scan_dirs
|
36
|
+
@@scan_dirs
|
37
|
+
end
|
38
|
+
|
18
39
|
def get(path)
|
19
40
|
build_request :get, path
|
20
41
|
end
|