unveil-ruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
1
+ namespace :unveil do
2
+ desc 'Activate a feature for a group'
3
+ task :activate_group, [:feature, :group] => :environment do |t, args|
4
+ with_exit do
5
+ Unveil::Feature.new(name: args.feature).activate_group(args.group)
6
+ end
7
+ end
8
+
9
+ desc 'Deactivate a feature for a group'
10
+ task :deactivate_group, [:feature, :group] => :environment do |t, args|
11
+ with_exit do
12
+ Unveil::Feature.new(name: args.feature).deactivate_group(args.group)
13
+ end
14
+ end
15
+
16
+ desc 'Activate a feature for a user'
17
+ task :activate_user, [:feature, :user_id] => :environment do |t, args|
18
+ with_exit do
19
+ Unveil::Feature.new(name: args.feature).activate_user(args.user_id)
20
+ end
21
+ end
22
+
23
+ desc 'Dectivate a feature for a user'
24
+ task :deactivate_user, [:feature, :user_id] => :environment do |t, args|
25
+ with_exit do
26
+ Unveil::Feature.new(name: args.feature).deactivate_user(args.user_id)
27
+ end
28
+ end
29
+
30
+ desc 'Activate a feature for a percentage of users'
31
+ task :activate_percentage, [:feature, :percentage] => :environment do |t, args|
32
+ with_exit do
33
+ Unveil::Feature.new(name: args.feature).activate_percentage(args.percentage)
34
+ end
35
+ end
36
+
37
+ desc "Dectivate a feature's percentage rollout"
38
+ task :deactivate_percentage, [:feature] => :environment do |t, args|
39
+ with_exit do
40
+ Unveil::Feature.new(name: args.feature).deactivate_percentage
41
+ end
42
+ end
43
+
44
+ desc "Deactivate a feature entirely"
45
+ task :deactivate_all, [:feature] => :environment do |t, args|
46
+ with_exit do
47
+ Unveil::Feature.new(name: args.feature).deactivate_all
48
+ end
49
+ end
50
+
51
+ desc "List all features"
52
+ task :features, [] => :environment do |t, args|
53
+ puts Unveil::App.new.feature_names
54
+ end
55
+
56
+ desc "Summarize all features"
57
+ task :summary, [] => :environment do |t, args|
58
+ Unveil::App.new.features.each do |feature|
59
+ puts "#{feature.name}\n"
60
+ puts " \033[31mGroups:\033[0m \033[32m#{feature.groups.join(', ')}\033[0m"
61
+ puts " \033[31mPercentage:\033[0m \033[32m#{feature.percentage}\033[0m"
62
+ puts " \033[31mUser Count:\033[0m \033[32m#{feature.user_count}\033[0m"
63
+ end
64
+ end
65
+
66
+ desc "List all groups"
67
+ task :groups, [] => :environment do |t, args|
68
+ puts Unveil::App.new.groups
69
+ end
70
+
71
+ namespace :groups do
72
+ desc "Create a group"
73
+ task :create, [:group] => :environment do |t, args|
74
+ with_exit do
75
+ Unveil::Group.new(args.group).save
76
+ end
77
+ end
78
+
79
+ desc "Delete a group"
80
+ task :delete, [:group] => :environment do |t, args|
81
+ with_exit do
82
+ Unveil::Group.new(args.group).destroy
83
+ end
84
+ end
85
+
86
+ desc "Add a user to a group"
87
+ task :add_user, [:group, :user_id] => :environment do |t, args|
88
+ with_exit do
89
+ Unveil::Group.new(args.group).add_user(args.user_id)
90
+ end
91
+ end
92
+
93
+ desc "Remove a user from a group"
94
+ task :remove_user, [:group, :user_id] => :environment do |t, args|
95
+ with_exit do
96
+ Unveil::Group.new(args.group).remove_user(args.user_id)
97
+ end
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ def with_exit(&block)
104
+ code = yield.code
105
+
106
+ if code == '200'
107
+ exit 0
108
+ else
109
+ puts "BAD RESPONSE: Response code #{code}"
110
+ exit 1
111
+ end
112
+ end
113
+ end
data/lib/unveil/app.rb CHANGED
@@ -5,6 +5,10 @@ module Unveil
5
5
  @attributes ||= JSON.parse(Unveil.get("").body)
6
6
  end
7
7
 
8
+ def groups(reload = false)
9
+ attributes(reload)['groups']
10
+ end
11
+
8
12
  def feature_names(reload = false)
9
13
  features(reload).collect(&:name)
10
14
  end
@@ -4,6 +4,10 @@ module Unveil
4
4
  @attributes = attrs
5
5
  end
6
6
 
7
+ def attributes
8
+ @attributes.with_indifferent_access
9
+ end
10
+
7
11
  def enabled(user_id)
8
12
  Unveil.get "features/#{name}/enabled/#{user_id}"
9
13
  end
@@ -39,8 +43,8 @@ module Unveil
39
43
  end
40
44
 
41
45
  def method_missing(method, *args, &block)
42
- if @attributes.has_key?(method.to_s)
43
- @attributes[method.to_s]
46
+ if attributes.has_key?(method)
47
+ attributes[method]
44
48
  else
45
49
  super
46
50
  end
@@ -0,0 +1,19 @@
1
+ module Unveil
2
+ module Controller
3
+ module Helpers
4
+ def self.included(base)
5
+ base.send :helper_method, :rollout?
6
+ base.send :helper_method, :unveil
7
+ end
8
+
9
+ def rollout?(feature)
10
+ return false unless current_user
11
+ ArRollout.active?(name, current_user)
12
+ end
13
+
14
+ def unveil
15
+ @unveil ||= Unveil::App.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Unveil
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/unveil.rb CHANGED
@@ -88,3 +88,9 @@ module Unveil
88
88
  end
89
89
  end
90
90
  end
91
+
92
+ class UnveilTask < Rails::Railtie
93
+ rake_tasks do
94
+ Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
95
+ end
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unveil-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -23,10 +23,12 @@ files:
23
23
  - LICENSE.txt
24
24
  - README.md
25
25
  - Rakefile
26
+ - lib/tasks/unveil_tasks.rake
26
27
  - lib/unveil.rb
27
28
  - lib/unveil/app.rb
28
29
  - lib/unveil/feature.rb
29
30
  - lib/unveil/group.rb
31
+ - lib/unveil/helpers.rb
30
32
  - lib/unveil/user.rb
31
33
  - lib/unveil/version.rb
32
34
  - unveil-ruby.gemspec