green_flag 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +138 -0
- data/MIT-LICENSE +20 -0
- data/README.md +43 -0
- data/Rakefile +38 -0
- data/app/assets/images/green_flag/.gitkeep +0 -0
- data/app/assets/javascripts/green_flag/admin/features.js +353 -0
- data/app/assets/javascripts/green_flag/admin/rules.js +2 -0
- data/app/assets/javascripts/green_flag/application.js +14 -0
- data/app/assets/stylesheets/green_flag/admin/features.css.scss +36 -0
- data/app/assets/stylesheets/green_flag/admin/rules.css.scss +3 -0
- data/app/assets/stylesheets/green_flag/application.css +13 -0
- data/app/controllers/green_flag/admin/feature_decision_summaries_controller.rb +33 -0
- data/app/controllers/green_flag/admin/features_controller.rb +32 -0
- data/app/controllers/green_flag/admin/rule_lists_controller.rb +28 -0
- data/app/controllers/green_flag/admin/white_list_users_controller.rb +39 -0
- data/app/controllers/green_flag/site_visitor_management.rb +51 -0
- data/app/helpers/green_flag/application_helper.rb +4 -0
- data/app/models/green_flag/feature.rb +84 -0
- data/app/models/green_flag/feature_decision.rb +77 -0
- data/app/models/green_flag/feature_event.rb +9 -0
- data/app/models/green_flag/rule.rb +66 -0
- data/app/models/green_flag/site_visitor.rb +49 -0
- data/app/models/green_flag/user_group.rb +8 -0
- data/app/models/green_flag/visitor_group.rb +60 -0
- data/app/views/green_flag/admin/features/index.html.erb +14 -0
- data/app/views/green_flag/admin/features/show.html.erb +144 -0
- data/app/views/layouts/green_flag/application.html.erb +25 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20140502112602_create_green_flag_site_visitors.rb +9 -0
- data/db/migrate/20140502221059_create_green_flag_features.rb +10 -0
- data/db/migrate/20140502221423_create_green_flag_feature_decisions.rb +13 -0
- data/db/migrate/20140505204611_add_visitor_code_to_site_visitors.rb +8 -0
- data/db/migrate/20140511045110_create_green_flag_rules.rb +12 -0
- data/db/migrate/20140513203728_set_default_percentage_in_green_flag_rules.rb +10 -0
- data/db/migrate/20140514202337_require_ordering_for_green_flag_rules.rb +13 -0
- data/db/migrate/20140516214909_add_restrictions_to_green_flag_rules.rb +13 -0
- data/db/migrate/20150211214159_create_green_flag_feature_events.rb +13 -0
- data/db/migrate/20150213191101_add_rule_id_to_green_flag_feature_decisions.rb +5 -0
- data/db/migrate/20150218035000_add_version_number_to_green_flag_rules.rb +9 -0
- data/db/migrate/20150218035805_add_version_number_to_green_flag_features.rb +9 -0
- data/db/migrate/20150218171852_add_version_number_to_green_flag_rules_indices.rb +19 -0
- data/green_flag.gemspec +34 -0
- data/green_flag.png +0 -0
- data/green_flag_small.png +0 -0
- data/lib/green_flag/engine.rb +16 -0
- data/lib/green_flag/version.rb +3 -0
- data/lib/green_flag.rb +4 -0
- data/lib/tasks/green_flag_tasks.rake +4 -0
- data/script/rails +8 -0
- data/spec/controllers/admin/feature_decision_summaries_controller_spec.rb +17 -0
- data/spec/controllers/admin/features_controller_spec.rb +21 -0
- data/spec/controllers/admin/rule_lists_controller_spec.rb +25 -0
- data/spec/controllers/admin/white_list_users_controller_spec.rb +15 -0
- data/spec/controllers/site_visitor_management_spec.rb +54 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +7 -0
- data/spec/dummy/app/controllers/feature_check_controller.rb +10 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +43 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20150726195118_create_users.rb +8 -0
- data/spec/dummy/db/migrate/20150726204409_add_email_to_users.rb +5 -0
- data/spec/dummy/db/schema.rb +78 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/log/development.log +8341 -0
- data/spec/dummy/log/test.log +34578 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/cache/assets/C47/3D0/sprockets%2F8f17c33229239b023190617bf2e915a3 +0 -0
- data/spec/dummy/tmp/cache/assets/C81/770/sprockets%2Fdbcf34796b062155788f0b550808541a +0 -0
- data/spec/dummy/tmp/cache/assets/C89/D60/sprockets%2F73cd073739a0655341b7278fae57518f +0 -0
- data/spec/dummy/tmp/cache/assets/CB6/8F0/sprockets%2F5ea0f1f2583683678e122a9a9391a80f +0 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/CE7/FF0/sprockets%2Fe45f3a7675a8c5a5b064117792bf5e28 +0 -0
- data/spec/dummy/tmp/cache/assets/D07/670/sprockets%2F761d03a66b753d628feccd12072c814c +0 -0
- data/spec/dummy/tmp/cache/assets/D10/860/sprockets%2F4582878dbb5b72bfa76615d31b34ed51 +0 -0
- data/spec/dummy/tmp/cache/assets/D13/270/sprockets%2F701a30cd450ae3cfa114092bafc16004 +0 -0
- data/spec/dummy/tmp/cache/assets/D15/C10/sprockets%2F6f42f843c916d7864a0dfa912fb3194a +0 -0
- data/spec/dummy/tmp/cache/assets/D18/860/sprockets%2Fce00769800ae939cebb28501947ea96f +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D4A/970/sprockets%2F2a7d3b403cbdd8b59d57d26964ea5768 +0 -0
- data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/D59/090/sprockets%2F88788ba6a64e6279624e5c2ff7eead53 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/D5C/330/sprockets%2Fd1b1c9a53f4a8a5827e5b02bf0e100e8 +0 -0
- data/spec/dummy/tmp/cache/assets/D68/760/sprockets%2Fea24808c41a3dff75b995b0f090e1a6a +0 -0
- data/spec/dummy/tmp/cache/assets/D6A/580/sprockets%2F18c12847aa1bb46ce9b5661f0e9e5fb0 +0 -0
- data/spec/dummy/tmp/cache/assets/DA1/210/sprockets%2F25a2979e392c8bc3adce7075cf19ab4b +0 -0
- data/spec/dummy/tmp/cache/assets/DA9/2C0/sprockets%2Ff95d82b2bbb6db8ffe1a87f67b415291 +0 -0
- data/spec/dummy/tmp/cache/assets/DB2/0C0/sprockets%2F95cf35cd3e97774df3c41ee0ef564a8d +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E07/200/sprockets%2F82a8ce7f5bcfb07f773df4cbfeb04762 +0 -0
- data/spec/dummy/tmp/cache/assets/E34/D30/sprockets%2F99c2d0bbd78f1b867beeb3a2eefda618 +0 -0
- data/spec/factories/green_flag/feature.rb +7 -0
- data/spec/factories/green_flag/rule.rb +9 -0
- data/spec/features/admin_spec.rb +16 -0
- data/spec/features/visitor_spec.rb +36 -0
- data/spec/models/green_flag/feature_decision_spec.rb +102 -0
- data/spec/models/green_flag/feature_event_spec.rb +4 -0
- data/spec/models/green_flag/feature_spec.rb +135 -0
- data/spec/models/green_flag/rule_spec.rb +107 -0
- data/spec/models/green_flag/site_visitor_spec.rb +95 -0
- data/spec/models/green_flag/user_group_spec.rb +24 -0
- data/spec/models/green_flag/visitor_group_spec.rb +81 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/controller_helpers.rb +7 -0
- metadata +359 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f72b8a42b9157e77de05c33652f3ae98ac042e8
|
4
|
+
data.tar.gz: 0c9627482a3ed2400c921e407dd1b2e1ddf19e87
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13d73c704f26582f0211687ae0d341577cfcf6efd9ff9153d633b931b2c9071399611705df196ef95b5ab20a2fee5e3e99009ff8fc3a40a4ac71149fc6c1fe98
|
7
|
+
data.tar.gz: 9e7593b849c503674f6520d9d55e89913afb4a3bfc9cee3b80689376aaccbbbb1315a96f7caa9935a252a3e9f59159b86c84579783f67db9e5005c686e88c57d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in green_flag.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# jquery-rails is used by the dummy application
|
9
|
+
gem "jquery-rails"
|
10
|
+
|
11
|
+
# Declare any dependencies that are still in development here instead of in
|
12
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
13
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
14
|
+
# your gem to rubygems.org.
|
15
|
+
|
16
|
+
# To use debugger
|
17
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
green_flag (0.1.0)
|
5
|
+
activerecord-concurrent-index (~> 0.0.1)
|
6
|
+
pg (~> 0.18)
|
7
|
+
rails (~> 3.2)
|
8
|
+
sass-rails (~> 3.2)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
actionmailer (3.2.22)
|
14
|
+
actionpack (= 3.2.22)
|
15
|
+
mail (~> 2.5.4)
|
16
|
+
actionpack (3.2.22)
|
17
|
+
activemodel (= 3.2.22)
|
18
|
+
activesupport (= 3.2.22)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
erubis (~> 2.7.0)
|
21
|
+
journey (~> 1.0.4)
|
22
|
+
rack (~> 1.4.5)
|
23
|
+
rack-cache (~> 1.2)
|
24
|
+
rack-test (~> 0.6.1)
|
25
|
+
sprockets (~> 2.2.1)
|
26
|
+
activemodel (3.2.22)
|
27
|
+
activesupport (= 3.2.22)
|
28
|
+
builder (~> 3.0.0)
|
29
|
+
activerecord (3.2.22)
|
30
|
+
activemodel (= 3.2.22)
|
31
|
+
activesupport (= 3.2.22)
|
32
|
+
arel (~> 3.0.2)
|
33
|
+
tzinfo (~> 0.3.29)
|
34
|
+
activerecord-concurrent-index (0.0.1)
|
35
|
+
activerecord
|
36
|
+
activeresource (3.2.22)
|
37
|
+
activemodel (= 3.2.22)
|
38
|
+
activesupport (= 3.2.22)
|
39
|
+
activesupport (3.2.22)
|
40
|
+
i18n (~> 0.6, >= 0.6.4)
|
41
|
+
multi_json (~> 1.0)
|
42
|
+
arel (3.0.3)
|
43
|
+
builder (3.0.4)
|
44
|
+
capybara (2.4.4)
|
45
|
+
mime-types (>= 1.16)
|
46
|
+
nokogiri (>= 1.3.3)
|
47
|
+
rack (>= 1.0.0)
|
48
|
+
rack-test (>= 0.5.4)
|
49
|
+
xpath (~> 2.0)
|
50
|
+
diff-lcs (1.2.5)
|
51
|
+
erubis (2.7.0)
|
52
|
+
factory_girl (4.1.0)
|
53
|
+
activesupport (>= 3.0.0)
|
54
|
+
factory_girl_rails (4.1.0)
|
55
|
+
factory_girl (~> 4.1.0)
|
56
|
+
railties (>= 3.0.0)
|
57
|
+
hike (1.2.3)
|
58
|
+
i18n (0.7.0)
|
59
|
+
journey (1.0.4)
|
60
|
+
jquery-rails (3.1.3)
|
61
|
+
railties (>= 3.0, < 5.0)
|
62
|
+
thor (>= 0.14, < 2.0)
|
63
|
+
json (1.8.3)
|
64
|
+
mail (2.5.4)
|
65
|
+
mime-types (~> 1.16)
|
66
|
+
treetop (~> 1.4.8)
|
67
|
+
mime-types (1.25.1)
|
68
|
+
mini_portile (0.6.2)
|
69
|
+
multi_json (1.11.2)
|
70
|
+
nokogiri (1.6.6.2)
|
71
|
+
mini_portile (~> 0.6.0)
|
72
|
+
pg (0.18.2)
|
73
|
+
polyglot (0.3.5)
|
74
|
+
rack (1.4.7)
|
75
|
+
rack-cache (1.2)
|
76
|
+
rack (>= 0.4)
|
77
|
+
rack-ssl (1.3.4)
|
78
|
+
rack
|
79
|
+
rack-test (0.6.3)
|
80
|
+
rack (>= 1.0)
|
81
|
+
rails (3.2.22)
|
82
|
+
actionmailer (= 3.2.22)
|
83
|
+
actionpack (= 3.2.22)
|
84
|
+
activerecord (= 3.2.22)
|
85
|
+
activeresource (= 3.2.22)
|
86
|
+
activesupport (= 3.2.22)
|
87
|
+
bundler (~> 1.0)
|
88
|
+
railties (= 3.2.22)
|
89
|
+
railties (3.2.22)
|
90
|
+
actionpack (= 3.2.22)
|
91
|
+
activesupport (= 3.2.22)
|
92
|
+
rack-ssl (~> 1.3.2)
|
93
|
+
rake (>= 0.8.7)
|
94
|
+
rdoc (~> 3.4)
|
95
|
+
thor (>= 0.14.6, < 2.0)
|
96
|
+
rake (10.4.2)
|
97
|
+
rdoc (3.12.2)
|
98
|
+
json (~> 1.4)
|
99
|
+
rspec-core (2.14.8)
|
100
|
+
rspec-expectations (2.14.5)
|
101
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
102
|
+
rspec-mocks (2.14.6)
|
103
|
+
rspec-rails (2.14.2)
|
104
|
+
actionpack (>= 3.0)
|
105
|
+
activemodel (>= 3.0)
|
106
|
+
activesupport (>= 3.0)
|
107
|
+
railties (>= 3.0)
|
108
|
+
rspec-core (~> 2.14.0)
|
109
|
+
rspec-expectations (~> 2.14.0)
|
110
|
+
rspec-mocks (~> 2.14.0)
|
111
|
+
sass (3.4.14)
|
112
|
+
sass-rails (3.2.6)
|
113
|
+
railties (~> 3.2.0)
|
114
|
+
sass (>= 3.1.10)
|
115
|
+
tilt (~> 1.3)
|
116
|
+
sprockets (2.2.3)
|
117
|
+
hike (~> 1.2)
|
118
|
+
multi_json (~> 1.0)
|
119
|
+
rack (~> 1.0)
|
120
|
+
tilt (~> 1.1, != 1.3.0)
|
121
|
+
thor (0.19.1)
|
122
|
+
tilt (1.4.1)
|
123
|
+
treetop (1.4.15)
|
124
|
+
polyglot
|
125
|
+
polyglot (>= 0.3.1)
|
126
|
+
tzinfo (0.3.44)
|
127
|
+
xpath (2.0.0)
|
128
|
+
nokogiri (~> 1.3)
|
129
|
+
|
130
|
+
PLATFORMS
|
131
|
+
ruby
|
132
|
+
|
133
|
+
DEPENDENCIES
|
134
|
+
capybara
|
135
|
+
factory_girl_rails
|
136
|
+
green_flag!
|
137
|
+
jquery-rails
|
138
|
+
rspec-rails
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014-2015 Webs, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# ![Green Flag Logo](./green_flag_small.png?raw=true) Green Flag
|
2
|
+
|
3
|
+
A feature-flag system that makes it *really easy* for application developers to add and manage features. You can roll out features to a percentage of your users, or you can define groups to see the new feature. Want to test a new feature on 50% of your premium-plan users named "Fred"? GreenFlag can do that.
|
4
|
+
|
5
|
+
Status: Recently extracted from a running application. Version 0.1 is just enough for us to use it as a gem. Some of the niceties (like this document) are pretty rough.
|
6
|
+
|
7
|
+
## New feature? Just do this:
|
8
|
+
|
9
|
+
In a controller or view, check for a feature:
|
10
|
+
```ruby
|
11
|
+
if feature_enabled?(:my_awesome_feature)
|
12
|
+
# New hotness
|
13
|
+
else
|
14
|
+
# Old stuff
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
That's it. You don't have to create a feature record (it's done automatically).
|
19
|
+
You don't have to figure out who should see the feature - that's set up in the admin web interface.
|
20
|
+
|
21
|
+
Features are off by default - so if you deploy your new code, no one will get the new hotness until you open it up with the admin web interface.
|
22
|
+
|
23
|
+
## How it works
|
24
|
+
|
25
|
+
TODO: explain about visitors, users and features.
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
### Requirements
|
30
|
+
- Rails 3
|
31
|
+
- Postgres
|
32
|
+
- `User` class, and `current_user` controller method
|
33
|
+
|
34
|
+
TODO: Some of this should be scripted with a generator
|
35
|
+
- Normal engine install process
|
36
|
+
- Install/run migrations
|
37
|
+
- Create an initializer to define visitor groups
|
38
|
+
- Mount admin in routes.rb
|
39
|
+
|
40
|
+
## Admin panel
|
41
|
+
|
42
|
+
TODO: explain all of the stuff on the admin panel
|
43
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'GreenFlag'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
|
35
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
36
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
37
|
+
|
38
|
+
task :default => :spec
|
File without changes
|
@@ -0,0 +1,353 @@
|
|
1
|
+
_.templateSettings = {
|
2
|
+
evaluate : /\{\[([\s\S]+?)\]\}/g,
|
3
|
+
interpolate : /\{\{([\s\S]+?)\}\}/g
|
4
|
+
};
|
5
|
+
|
6
|
+
|
7
|
+
// NAMESPACE ------------------------------------------------------------------
|
8
|
+
var GreenFlag = GreenFlag || {};
|
9
|
+
|
10
|
+
// APPLICATION ----------------------------------------------------------------
|
11
|
+
GreenFlag.FeatureEditor = new Backbone.Marionette.Application();
|
12
|
+
|
13
|
+
GreenFlag.FeatureEditor.addRegions({
|
14
|
+
whiteList: '#white-list',
|
15
|
+
rules: '#rules',
|
16
|
+
yourStatus: '#your-status',
|
17
|
+
decisions: '#decisions',
|
18
|
+
});
|
19
|
+
|
20
|
+
GreenFlag.FeatureEditor.addInitializer(function(options){
|
21
|
+
new GreenFlag.PostImageController(options);
|
22
|
+
});
|
23
|
+
|
24
|
+
// CONTROLLER ----------------------------------------------------------------
|
25
|
+
GreenFlag.PostImageController = Backbone.Marionette.Controller.extend({
|
26
|
+
initialize: function(options) {
|
27
|
+
this.feature = options.feature;
|
28
|
+
this.setupRules(this.feature, options.allVisitorGroups);
|
29
|
+
this.setupWhiteList(this.feature);
|
30
|
+
this.setupYourStatus(this.feature);
|
31
|
+
this.setupDecisions(this.feature);
|
32
|
+
},
|
33
|
+
|
34
|
+
setupRules: function(feature, allVisitorGroups) {
|
35
|
+
var ruleList = new GreenFlag.RuleList([], {
|
36
|
+
feature: feature,
|
37
|
+
});
|
38
|
+
window.ruleList = ruleList;
|
39
|
+
var rulesView = new GreenFlag.RulesView({
|
40
|
+
collection: ruleList,
|
41
|
+
allVisitorGroups: allVisitorGroups,
|
42
|
+
});
|
43
|
+
GreenFlag.FeatureEditor.rules.show(rulesView);
|
44
|
+
ruleList.fetch();
|
45
|
+
},
|
46
|
+
|
47
|
+
setupWhiteList: function(feature) {
|
48
|
+
var whiteList = new GreenFlag.WhiteList([], {
|
49
|
+
feature: feature,
|
50
|
+
});
|
51
|
+
var whiteListView = new GreenFlag.WhiteListView({
|
52
|
+
collection: whiteList,
|
53
|
+
});
|
54
|
+
GreenFlag.FeatureEditor.whiteList.show(whiteListView);
|
55
|
+
whiteList.fetch();
|
56
|
+
},
|
57
|
+
|
58
|
+
setupYourStatus: function(feature) {
|
59
|
+
var status = new GreenFlag.YourStatus({
|
60
|
+
feature: feature,
|
61
|
+
});
|
62
|
+
var yourStatusView = new GreenFlag.YourStatusView({
|
63
|
+
model: status
|
64
|
+
});
|
65
|
+
GreenFlag.FeatureEditor.yourStatus.show(yourStatusView);
|
66
|
+
status.fetch();
|
67
|
+
},
|
68
|
+
|
69
|
+
setupDecisions: function(feature) {
|
70
|
+
var decisionSummary = new GreenFlag.DecisionSummary({
|
71
|
+
feature: feature,
|
72
|
+
enabled: 0,
|
73
|
+
disabled: 0,
|
74
|
+
})
|
75
|
+
var decisionsView = new GreenFlag.DecisionsView({
|
76
|
+
model: decisionSummary,
|
77
|
+
});
|
78
|
+
GreenFlag.FeatureEditor.decisions.show(decisionsView);
|
79
|
+
decisionSummary.fetch();
|
80
|
+
},
|
81
|
+
});
|
82
|
+
|
83
|
+
// MODELS ----------------------------------------------------------------
|
84
|
+
GreenFlag.WhiteList = Backbone.Collection.extend({
|
85
|
+
url: function() {
|
86
|
+
return '/green_flag/admin/features/'+this.feature.id+'/white_list_users';
|
87
|
+
},
|
88
|
+
|
89
|
+
initialize: function(models, options) {
|
90
|
+
this.feature = options.feature;
|
91
|
+
},
|
92
|
+
});
|
93
|
+
|
94
|
+
GreenFlag.RuleList = Backbone.Collection.extend({
|
95
|
+
|
96
|
+
url: function() {
|
97
|
+
return '/green_flag/admin/features/'+this.feature.id+'/rule_list';
|
98
|
+
},
|
99
|
+
|
100
|
+
initialize: function(models, options) {
|
101
|
+
this.feature = options.feature;
|
102
|
+
|
103
|
+
this.isDirty = false;
|
104
|
+
this.on('change add remove sort', this.setDirty, this);
|
105
|
+
this.on('sync', this.setClean, this);
|
106
|
+
},
|
107
|
+
|
108
|
+
saveRules: function() {
|
109
|
+
Backbone.sync('update', this, {
|
110
|
+
success: this.setClean,
|
111
|
+
error: this.setInvalid,
|
112
|
+
context: this,
|
113
|
+
});
|
114
|
+
},
|
115
|
+
|
116
|
+
setDirty: function() {
|
117
|
+
this._setDirtyState(true);
|
118
|
+
},
|
119
|
+
|
120
|
+
setClean: function() {
|
121
|
+
if(this.isInvalid) {
|
122
|
+
this.isInvalid = false;
|
123
|
+
this.trigger('change:isInvalid');
|
124
|
+
}
|
125
|
+
this._setDirtyState(false);
|
126
|
+
},
|
127
|
+
|
128
|
+
setInvalid: function() {
|
129
|
+
if(!this.isInvalid) {
|
130
|
+
this.isInvalid = true;
|
131
|
+
this.trigger('change:isInvalid');
|
132
|
+
}
|
133
|
+
},
|
134
|
+
|
135
|
+
_setDirtyState: function(newIsDirty) {
|
136
|
+
newIsDirty = !!newIsDirty;
|
137
|
+
if(newIsDirty !== this.isDirty) {
|
138
|
+
this.isDirty = newIsDirty;
|
139
|
+
this.trigger('change:isDirty');
|
140
|
+
}
|
141
|
+
},
|
142
|
+
|
143
|
+
sortBy: function(rule) {
|
144
|
+
return rule.get('order_by');
|
145
|
+
},
|
146
|
+
|
147
|
+
nextOrderBy: function() {
|
148
|
+
if(this.isEmpty()) {
|
149
|
+
return 0;
|
150
|
+
}
|
151
|
+
var maxOrder = this.last().get('order_by');
|
152
|
+
maxOrder = parseInt(maxOrder, 10);
|
153
|
+
return maxOrder + 1;
|
154
|
+
}
|
155
|
+
});
|
156
|
+
|
157
|
+
GreenFlag.YourStatus = Backbone.Model.extend({
|
158
|
+
url: function() {
|
159
|
+
return '/green_flag/admin/features/'+this.feature.id+'/current_visitor_status';
|
160
|
+
},
|
161
|
+
|
162
|
+
initialize: function(attributes, options) {
|
163
|
+
this.feature = attributes.feature;
|
164
|
+
},
|
165
|
+
});
|
166
|
+
|
167
|
+
GreenFlag.DecisionSummary = Backbone.Model.extend({
|
168
|
+
url: function() {
|
169
|
+
return '/green_flag/admin/features/'+this.feature.id+'/feature_decision_summary';
|
170
|
+
},
|
171
|
+
|
172
|
+
initialize: function(attributes, options) {
|
173
|
+
this.feature = attributes.feature;
|
174
|
+
},
|
175
|
+
|
176
|
+
isNew: function() { return false; }
|
177
|
+
});
|
178
|
+
|
179
|
+
// VIEWS ----------------------------------------------------------------
|
180
|
+
GreenFlag.WhiteListUserView = Backbone.Marionette.ItemView.extend({
|
181
|
+
template: '#white-list-user-template',
|
182
|
+
className: 'list-group-item',
|
183
|
+
events: {
|
184
|
+
'click .destroy-user': 'destroyUser'
|
185
|
+
},
|
186
|
+
|
187
|
+
destroyUser: function() {
|
188
|
+
this.model.destroy({wait: true});
|
189
|
+
}
|
190
|
+
});
|
191
|
+
|
192
|
+
GreenFlag.WhiteListView = Backbone.Marionette.CompositeView.extend({
|
193
|
+
template: "#white-list-template",
|
194
|
+
itemView: GreenFlag.WhiteListUserView,
|
195
|
+
itemViewContainer: '.white-list-user-list',
|
196
|
+
|
197
|
+
events: {
|
198
|
+
'click .add-user': 'addUser',
|
199
|
+
'keypress .user-email': 'checkForEnter',
|
200
|
+
},
|
201
|
+
|
202
|
+
addUser: function() {
|
203
|
+
var email = this.$('.user-email').val();
|
204
|
+
this.collection.create({ email: email }, {
|
205
|
+
wait: true,
|
206
|
+
success: this.clearForm,
|
207
|
+
error: this.errorMessage
|
208
|
+
});
|
209
|
+
},
|
210
|
+
|
211
|
+
checkForEnter: function(e) {
|
212
|
+
if(e.keyCode === 13) {
|
213
|
+
this.addUser();
|
214
|
+
}
|
215
|
+
},
|
216
|
+
|
217
|
+
clearForm: function() {
|
218
|
+
this.$('.user-email').val('');
|
219
|
+
this.$('.error-message').hide();
|
220
|
+
this.$('.user-email').focus();
|
221
|
+
},
|
222
|
+
errorMessage: function() {
|
223
|
+
this.$('.error-message').show();
|
224
|
+
this.$('.user-email').focus();
|
225
|
+
}
|
226
|
+
});
|
227
|
+
|
228
|
+
GreenFlag.CurrentRuleView = Backbone.Marionette.ItemView.extend({
|
229
|
+
template: '#current-rule-template',
|
230
|
+
tagName: 'tr',
|
231
|
+
|
232
|
+
events: {
|
233
|
+
'change .rule-percent': 'setPercent',
|
234
|
+
'keypress .rule-percent': 'setPercent',
|
235
|
+
'click .remove-rule': 'removeRule',
|
236
|
+
},
|
237
|
+
|
238
|
+
setPercent: function() {
|
239
|
+
var pct = this.$('.rule-percent').val();
|
240
|
+
this.model.set({percentage: pct});
|
241
|
+
},
|
242
|
+
|
243
|
+
removeRule: function() {
|
244
|
+
this.model.collection.remove(this.model);
|
245
|
+
},
|
246
|
+
});
|
247
|
+
|
248
|
+
GreenFlag.RulesView = Backbone.Marionette.CompositeView.extend({
|
249
|
+
template: '#rules-template',
|
250
|
+
itemView: GreenFlag.CurrentRuleView,
|
251
|
+
itemViewContainer: '.current-rules',
|
252
|
+
|
253
|
+
events: {
|
254
|
+
'click .add-rule': 'addRule',
|
255
|
+
'click .save-rules': 'saveRules',
|
256
|
+
'click .revert-rules': 'revertRules',
|
257
|
+
},
|
258
|
+
|
259
|
+
initialize: function(options) {
|
260
|
+
this.allVisitorGroups = options.allVisitorGroups || [];
|
261
|
+
this.listenTo(this.collection, 'change:isDirty', this.setSaveButtons, this);
|
262
|
+
this.listenTo(this.collection, 'change:isInvalid', this.setInvalidMessage, this);
|
263
|
+
this.listenTo(this.collection, 'sync', this.render);
|
264
|
+
},
|
265
|
+
|
266
|
+
saveRules: function() {
|
267
|
+
this.collection.saveRules();
|
268
|
+
},
|
269
|
+
|
270
|
+
revertRules: function() {
|
271
|
+
this.collection.fetch();
|
272
|
+
},
|
273
|
+
|
274
|
+
addRule: function() {
|
275
|
+
var groupIndex = this.$('select.group-keys').val();
|
276
|
+
var group = this.allVisitorGroups[groupIndex];
|
277
|
+
this.collection.add({
|
278
|
+
group_key: group.key,
|
279
|
+
group_description: group.description,
|
280
|
+
percentage: 0,
|
281
|
+
order_by: this.collection.nextOrderBy(),
|
282
|
+
});
|
283
|
+
},
|
284
|
+
|
285
|
+
setSaveButtons: function() {
|
286
|
+
if(this.collection.isDirty) {
|
287
|
+
this.$('.save-buttons').show(300);
|
288
|
+
} else {
|
289
|
+
this.$('.save-buttons').hide();
|
290
|
+
}
|
291
|
+
},
|
292
|
+
|
293
|
+
setInvalidMessage: function() {
|
294
|
+
if(this.collection.isInvalid) {
|
295
|
+
this.$('.invalid-message').show(300);
|
296
|
+
} else {
|
297
|
+
this.$('.invalid-message').hide();
|
298
|
+
}
|
299
|
+
},
|
300
|
+
|
301
|
+
onRender: function() {
|
302
|
+
var selectEl = this.$('select.group-keys');
|
303
|
+
_.each(this.allVisitorGroups, function(group, i) {
|
304
|
+
var key = group.key;
|
305
|
+
selectEl.append("<option value=\""+i+"\">"+key+"</option>")
|
306
|
+
});
|
307
|
+
this.setSaveButtons();
|
308
|
+
this.setInvalidMessage();
|
309
|
+
}
|
310
|
+
});
|
311
|
+
|
312
|
+
GreenFlag.YourStatusView = Backbone.Marionette.ItemView.extend({
|
313
|
+
template: '#your-status-template',
|
314
|
+
modelEvents: {
|
315
|
+
'change': 'render',
|
316
|
+
},
|
317
|
+
|
318
|
+
serializeData: function() {
|
319
|
+
return _.extend({ labelClass: this.labelClass() }, this.model.toJSON());
|
320
|
+
},
|
321
|
+
|
322
|
+
labelClass: function() {
|
323
|
+
var status = this.model.get('status');
|
324
|
+
var label = 'label-default';
|
325
|
+
if(status === 'Enabled') {
|
326
|
+
label = 'label-success';
|
327
|
+
} else if(status === 'Disabled') {
|
328
|
+
label = 'label-warning';
|
329
|
+
}
|
330
|
+
|
331
|
+
return label;
|
332
|
+
},
|
333
|
+
});
|
334
|
+
|
335
|
+
GreenFlag.DecisionsView = Backbone.Marionette.ItemView.extend({
|
336
|
+
template: '#decisions-template',
|
337
|
+
modelEvents: {
|
338
|
+
'change': 'render',
|
339
|
+
},
|
340
|
+
events: {
|
341
|
+
'click .forget-decisions-enabled': 'forgetDecisionsEnabled',
|
342
|
+
'click .forget-decisions-disabled': 'forgetDecisionsDisabled',
|
343
|
+
},
|
344
|
+
|
345
|
+
forgetDecisionsEnabled: function() {
|
346
|
+
this.model.save({ forget_enabled: true });
|
347
|
+
},
|
348
|
+
|
349
|
+
forgetDecisionsDisabled: function() {
|
350
|
+
this.model.save({ forget_disabled: true });
|
351
|
+
},
|
352
|
+
|
353
|
+
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery_ujs
|
14
|
+
//= require_tree .
|
@@ -0,0 +1,36 @@
|
|
1
|
+
// Place all the styles related to the green_flag/admin/features controller here.
|
2
|
+
// They will automatically be included in application.css.
|
3
|
+
// You can use Sass (SCSS) here: http://sass-lang.com/
|
4
|
+
|
5
|
+
@media (min-width: 768px) {
|
6
|
+
.container {
|
7
|
+
max-width: 768px;
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
.header {
|
12
|
+
border-bottom: 1px solid #e5e5e5;
|
13
|
+
}
|
14
|
+
|
15
|
+
.percentage {
|
16
|
+
white-space: nowrap;
|
17
|
+
}
|
18
|
+
|
19
|
+
ul.decisions-made-summary {
|
20
|
+
|
21
|
+
padding: 0;
|
22
|
+
margin: 10px;
|
23
|
+
|
24
|
+
li {
|
25
|
+
display: inline-block;
|
26
|
+
list-style-type: none;
|
27
|
+
width: 45%;
|
28
|
+
text-align: center;
|
29
|
+
vertical-align: middle;
|
30
|
+
}
|
31
|
+
|
32
|
+
.decision-number {
|
33
|
+
font-weight: 500;
|
34
|
+
font-size: 24px;
|
35
|
+
}
|
36
|
+
}
|