safety_cone 1.1.0 → 1.2.0

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: b1a84c4f47818100346deb5406a5e31349fbe369
4
- data.tar.gz: 1300636c1ce0920c16f9ecb14e727e373fc0fcaf
3
+ metadata.gz: 2101ef8045b6a171f2bf74adf69ed729b6b7c3d4
4
+ data.tar.gz: 2c4021a527d67509b7a5d43ac7ceac34183ec3de
5
5
  SHA512:
6
- metadata.gz: 391806f295ceb89632b0f65bf3b82be0a0230993c2a0fdf579176d4efd2265c9f3d9dcf352bc2dddefe22c8eb43f11b4333172486b204ae592fd7184609e76ee
7
- data.tar.gz: 72411e11648c4774b0579870172235acd163db7d3cfbf740ffecb3e0dce14fb33b4ed20c428d24ebfddbde70da4af4ad2b79c75085bdfa7bc2ae8e7b980a86da
6
+ metadata.gz: 7894f42411f05db74d1089afa3fd57197fb82f68bbb007396828218f16e845aeec58aa6206f137d25eab754bc307bf55266ba97d16f6f689344563b30c42382c
7
+ data.tar.gz: ca2c5ee05fde598914b861afa0913ccd9e6a92b76197863d8bbffaf2da4e89168cbefccfef0a1ea3425735ffafe620eb59a3a7296017bd5d43be62f56a5558e7
data/README.md CHANGED
@@ -41,13 +41,22 @@ SafetyCone.configure do |config|
41
41
  method: 'POST',
42
42
  name: 'All POST requests'
43
43
  )
44
+
45
+ # Feature flipper
46
+ config.add(
47
+ feature: :record_search,
48
+ name: 'Search'
49
+ )
50
+
51
+ # This config will provide a view helper record_search?
52
+ # Which can be used in the view to display a div or not
44
53
  end
45
54
  ```
46
55
 
47
56
  In routes add
48
57
 
49
58
  ```
50
- mount SafetyCone::Engine, :at => '/safety_cone'
59
+ mount SafetyCone::Engine, :as => '/safety_cone'
51
60
  ```
52
61
 
53
62
  In ApplicationController
@@ -71,7 +80,14 @@ In View
71
80
 
72
81
  <% if safetycone_alert %>
73
82
  <div class="alert"><%= safetycone_alert %></div>
74
- <% end %>
83
+ <% end %>
84
+
85
+ <!-- Feature Flipper -->
86
+ <% if record_search? %>
87
+ <div>Search Records</div>
88
+ <% else %>
89
+ <div>Search Records</div>
90
+ <% end %>
75
91
  </div>
76
92
  ```
77
93
 
@@ -93,7 +109,7 @@ SafetyCone.configure do |config|
93
109
  type: :block
94
110
  )
95
111
 
96
- # This is a controller action specific warning. But with no measures to prevent this action
112
+ # This is a controller action specific warning. But with no types to prevent this action
97
113
  config.add(
98
114
  controller: :users,
99
115
  action: :new,
@@ -126,7 +142,11 @@ end
126
142
 
127
143
 
128
144
  ## Contributing
129
- Contribution directions go here.
145
+ 1. Fork it
146
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
147
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
148
+ 4. Push to the branch (`git push origin my-new-feature`)
149
+ 5. Create new Pull Request
130
150
 
131
151
  ## License
132
152
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -14,8 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
-
18
-
19
17
  APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
20
18
  load 'rails/tasks/engine.rake'
21
19
 
@@ -3,11 +3,58 @@
3
3
  They will automatically be included in application.css.
4
4
  */
5
5
 
6
+ html {
7
+ font-family: sans-serif;
8
+ }
9
+
6
10
  body {
7
- margin-top: 2rem;
8
11
  background-color: #e0e0e0;
9
12
  }
10
13
 
14
+ .wrapper {
15
+ display: grid;
16
+ justify-content: center;
17
+ }
18
+
19
+ .header {
20
+ display: grid;
21
+ width: 60rem;
22
+ grid-template-columns: 1fr 10fr 1fr;
23
+ border-bottom: 1px solid #aaaaaa;
24
+ margin-bottom: 2rem;
25
+ }
26
+
27
+ .header .logo {
28
+ margin-top: 1rem;
29
+ justify-self: center;
30
+ }
31
+
32
+ .grid {
33
+ display: grid;
34
+ width: 60rem;
35
+ grid-template-columns: 2fr 1fr 1fr;
36
+ grid-gap: 1rem;
37
+ margin-bottom: 2rem;
38
+ }
39
+
40
+
41
+ .bottom-grid {
42
+ display: grid;
43
+ width: 60rem;
44
+ grid-template-columns: 2fr 1fr 1fr;
45
+ grid-gap: 1rem;
46
+ margin-bottom: 2rem;
47
+ }
48
+
49
+ .col {
50
+ grid-column: 1/4;
51
+ grid-row: 1/4;
52
+ }
53
+
54
+ .form {
55
+ display: grid;
56
+ }
57
+
11
58
  .card {
12
59
  padding: 2rem;
13
60
  display: block;
@@ -23,7 +70,7 @@ body {
23
70
  .card, .btn {
24
71
  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
25
72
  }
26
- .card:hover{
73
+ .card:hover {
27
74
  box-shadow: 0 3px 3px 0 rgba(0, 0, 0, 0.14), 0 1px 7px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -1px rgba(0, 0, 0, 0.2);
28
75
  }
29
76
 
@@ -40,45 +87,16 @@ body {
40
87
  background-color: #FF8A65 !important;
41
88
  }
42
89
 
43
- html {
44
- font-family: sans-serif;
45
- }
46
-
47
- hr {
48
- box-sizing: content-box;
49
- height: 0;
50
- }
51
-
52
- .container {
53
- margin: 0 auto;
54
- max-width: 1280px;
55
- width: 90%;
56
- }
57
- .row .col {
58
- float: left;
59
- box-sizing: border-box;
60
- padding: 0 0.75rem;
61
- min-height: 1px;
62
- }
63
- h4 {
64
- font-size: 2.28rem;
65
- line-height: 110%;
66
- margin: 1.14rem 0 0.912rem 0;
67
- text-align: center;
68
- }
69
-
70
- h5 {
71
- font-size: 1.64rem;
72
- line-height: 110%;
73
- margin: 0.82rem 0 0.656rem 0;
74
- text-align: center;
90
+ h3 {
91
+ font-size: 1.86rem;
92
+ margin-left: 2rem;
75
93
  }
76
94
 
77
95
  h6 {
78
96
  font-size: 1rem;
79
97
  line-height: 110%;
80
98
  margin: 0.5rem 0 0.4rem 0;
81
- text-align: center;
99
+ text-align: center;
82
100
  }
83
101
 
84
102
  .chip {
@@ -116,46 +134,22 @@ h6 {
116
134
  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
117
135
  }
118
136
 
119
- .btn:hover {
120
- background-color: #2bbbad;
121
- box-shadow: 0 3px 3px 0 rgba(0, 0, 0, 0.14), 0 1px 7px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -1px rgba(0, 0, 0, 0.2);
122
- }
123
-
124
- .row .col.s3 {
125
- width: 25%;
126
- margin-left: auto;
127
- left: auto;
128
- right: auto;
129
- }
130
-
131
- .row .col.s6 {
132
- width: 50%;
133
- margin-left: auto;
134
- left: auto;
135
- right: auto;
136
- }
137
-
138
- .row .col.s12 {
137
+ .btn.expand {
139
138
  width: 100%;
140
- margin-left: auto;
141
- left: auto;
142
- right: auto;
143
139
  }
144
140
 
145
- .row .col.offset-s3 {
146
- margin-left: 25%;
147
- }
148
- .row .col.offset-s4 {
149
- margin-left: 33.33333333%;
141
+ .btn.back {
142
+ align-self: center;
150
143
  }
151
- .row .col.offset-s4 {
152
- left: 33.3333333333%;
153
- }
154
-
155
144
 
156
145
  .grey {
157
146
  background: #DCDCDC;
158
147
  }
148
+
149
+ .dark-grey {
150
+ background: #AAAAAA;
151
+ }
152
+
159
153
  .grey:hover {
160
154
  background: #BABABA;
161
155
  }
@@ -176,6 +170,7 @@ input[type=text] {
176
170
  transition: all 0.3s;
177
171
  color: white;
178
172
  }
173
+
179
174
  .input-field .input-label{
180
175
  color: #9e9e9e;
181
176
  position: absolute;
@@ -195,6 +190,7 @@ input[type=text]:focus {
195
190
  border-bottom: 2px solid #26a69a!important;
196
191
  transition: .2s ease-out;
197
192
  }
193
+
198
194
  input[type=text]:focus + label {
199
195
  margin-top: -20px!important;
200
196
  color: #26a69a!important;
@@ -215,23 +211,22 @@ input[type=text]:focus + label {
215
211
 
216
212
  input[type="radio"]:not(:checked),
217
213
  [type="radio"]:checked {
218
- position: absolute;
219
- left: -9999px;
220
- opacity: 0;
214
+ position: absolute;
215
+ left: -9999px;
216
+ opacity: 0;
221
217
  }
222
218
 
223
219
  [type="radio"]:not(:checked) + label,
224
220
  [type="radio"]:checked + label {
225
- position: relative;
226
- padding-left: 35px;
227
- cursor: pointer;
228
- display: inline-block;
229
- height: 25px;
230
- line-height: 30px;
231
- font-size: 1rem;
232
- transition: .28s ease;
233
- /* webkit (konqueror) browsers */
234
- -webkit-user-select: none;
221
+ position: relative;
222
+ padding-left: 35px;
223
+ cursor: pointer;
224
+ display: inline-block;
225
+ height: 25px;
226
+ line-height: 30px;
227
+ font-size: 1rem;
228
+ transition: .28s ease;
229
+ -webkit-user-select: none;
235
230
  -moz-user-select: none;
236
231
  -ms-user-select: none;
237
232
  user-select: none;
@@ -239,15 +234,15 @@ transition: .28s ease;
239
234
 
240
235
  [type="radio"] + label:before,
241
236
  [type="radio"] + label:after {
242
- content: '';
243
- position: absolute;
244
- left: 0;
245
- top: 0;
246
- margin: 4px;
247
- width: 16px;
248
- height: 16px;
249
- z-index: 0;
250
- transition: .28s ease;
237
+ content: '';
238
+ position: absolute;
239
+ left: 0;
240
+ top: 0;
241
+ margin: 4px;
242
+ width: 16px;
243
+ height: 16px;
244
+ z-index: 0;
245
+ transition: .28s ease;
251
246
  }
252
247
 
253
248
  /* Unchecked styles */
@@ -257,42 +252,46 @@ transition: .28s ease;
257
252
  [type="radio"]:checked + label:after,
258
253
  [type="radio"].with-gap:checked + label:before,
259
254
  [type="radio"].with-gap:checked + label:after {
260
- border-radius: 50%;
255
+ border-radius: 50%;
261
256
  }
262
257
 
263
258
  [type="radio"]:not(:checked) + label:before,
264
259
  [type="radio"]:not(:checked) + label:after {
265
- border: 2px solid #5a5a5a;
260
+ border: 2px solid #5a5a5a;
266
261
  }
267
262
 
268
263
  [type="radio"]:not(:checked) + label:after {
269
- -webkit-transform: scale(0);
270
- transform: scale(0);
264
+ -webkit-transform: scale(0);
265
+ transform: scale(0);
271
266
  }
272
267
 
273
268
  /* Checked styles */
274
269
  [type="radio"]:checked + label:before {
275
- border: 2px solid transparent;
270
+ border: 2px solid transparent;
276
271
  }
277
272
 
278
273
  [type="radio"]:checked + label:after,
279
274
  [type="radio"].with-gap:checked + label:before,
280
275
  [type="radio"].with-gap:checked + label:after {
281
- border: 2px solid #26a69a;
276
+ border: 2px solid #26a69a;
282
277
  }
283
278
 
284
279
  [type="radio"]:checked + label:after,
285
280
  [type="radio"].with-gap:checked + label:after {
286
- background-color: #26a69a;
281
+ background-color: #26a69a;
287
282
  }
288
283
 
289
284
  [type="radio"]:checked + label:after {
290
- -webkit-transform: scale(1.02);
291
- transform: scale(1.02);
285
+ -webkit-transform: scale(1.02);
286
+ transform: scale(1.02);
292
287
  }
293
288
 
294
289
  /* Focused styles */
295
290
  [type="radio"].tabbed:focus + label:before {
296
- box-shadow: 0 0 0 10px rgba(0, 0, 0, 0.1);
297
- color: red!Important;
291
+ box-shadow: 0 0 0 10px rgba(0, 0, 0, 0.1);
292
+ color: red!Important;
293
+ }
294
+
295
+ .red {
296
+ background-color: #D52618 !important;
298
297
  }
@@ -1,5 +1,10 @@
1
1
  module SafetyCone
2
2
  class ApplicationController < ActionController::Base
3
3
  protect_from_forgery with: :exception
4
+
5
+ unless Rails.env.test?
6
+ http_basic_authenticate_with name: SafetyCone.auth[:username],
7
+ password: SafetyCone.auth[:password] if (SafetyCone.auth[:username] && SafetyCone.auth[:password])
8
+ end
4
9
  end
5
10
  end
@@ -1,28 +1,7 @@
1
- require_dependency "safety_cone/application_controller"
1
+ require_dependency 'safety_cone/application_controller'
2
2
 
3
3
  module SafetyCone
4
4
  class ConesController < ApplicationController
5
- unless Rails.env.test?
6
- http_basic_authenticate_with name: SafetyCone.auth[:username],
7
- password: SafetyCone.auth[:password] if (SafetyCone.auth[:username] && SafetyCone.auth[:password])
8
- end
9
-
10
- def index
11
- @cones = SafetyCone.cones
12
- end
13
-
14
- def edit
15
- cone = SafetyCone.cones[params[:id].to_sym]
16
- @cone = Cone.new(params[:id], cone)
17
- @cone.fetch
18
- end
19
-
20
- def update
21
- cone = SafetyCone.cones[params[:id].to_sym]
22
- mereged_params = cone.merge(params[:cone].symbolize_keys)
23
- Cone.new(params[:id], mereged_params).save
24
-
25
- redirect_to cones_path
26
- end
5
+ def index; end
27
6
  end
28
7
  end
@@ -0,0 +1,15 @@
1
+ require_dependency 'safety_cone/application_controller'
2
+
3
+ module SafetyCone
4
+ class FeaturesController < ApplicationController
5
+ def update
6
+ feature = SafetyCone.features[params[:id].to_i]
7
+
8
+ redis = SafetyCone.redis
9
+ redis_key = "safety::cone::#{feature[:feature]}"
10
+ redis.set(redis_key, params[:state])
11
+
12
+ redirect_to cones_path
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require_dependency 'safety_cone/application_controller'
2
+
3
+ module SafetyCone
4
+ class PathsController < ApplicationController
5
+ def edit
6
+ path = SafetyCone.paths[params[:id].to_sym]
7
+ @path = Path.new(params[:id], path)
8
+ @path.fetch
9
+ end
10
+
11
+ def update
12
+ path = SafetyCone.paths[params[:id].to_sym]
13
+ mereged_params = path.merge(params[:path].symbolize_keys)
14
+ Path.new(params[:id], mereged_params).save
15
+
16
+ redirect_to cones_path
17
+ end
18
+ end
19
+ end
@@ -1,9 +1,15 @@
1
1
  module SafetyCone
2
2
  module ConesHelper
3
+ include ViewHelpers
4
+
3
5
  def status(key)
4
- cone = Cone.new(key, {})
6
+ cone = Path.new(key, {})
5
7
  cone.fetch
6
8
  cone.type
7
9
  end
10
+
11
+ def feature_status(key)
12
+ feature?(key)
13
+ end
8
14
  end
9
15
  end
@@ -1,5 +1,5 @@
1
1
  module SafetyCone
2
- class Cone
2
+ class Path
3
3
  attr_accessor :name, :controller, :action,
4
4
  :method, :message, :type,
5
5
  :key, :redis
@@ -2,17 +2,14 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Safety Cone</title>
5
- <%= stylesheet_link_tag "safety_cone/application", media: 'all' %>
5
+ <%= stylesheet_link_tag 'safety_cone/application', media: 'all' %>
6
6
  </head>
7
7
  <body>
8
- <div class="container">
9
- <div class="row">
10
- <div class="col s1 offset-s4">
11
- <%= image_tag('safety_cone/logo.png', size: "80x80") %>
12
- </div>
13
- <div class="col s4 center">
14
- <h4>Safety Cone</h4>
15
- </div>
8
+ <div class='wrapper'>
9
+ <div class='header'>
10
+ <%= image_tag('safety_cone/logo.png', size: '60x60', class: 'logo') %>
11
+ <h3>Safety Cone</h3>
12
+ <%= link_to 'home', '/', class: 'btn back dark-grey' %>
16
13
  </div>
17
14
  <%= yield %>
18
15
  </div>
@@ -1,24 +1,35 @@
1
- <div class="row">
2
- <div class="col s6 offset-s3">
3
- <hr />
4
- <% @cones.each do |cone, options| %>
5
-
6
- <div class="row">
7
- <div class="col s6">
8
- <%= options[:name] %>
9
- </div>
10
-
11
- <div class="col s3">
12
- <div class="chip status-<%= status(cone) %>">
13
- <%= status(cone) %>
14
- </div>
15
- </div>
16
-
17
- <div class="col s3">
18
- <%= link_to 'edit', edit_cone_path(cone), class: 'waves-effect waves-light btn' %>
19
- </div>
20
- </div>
21
- <% end %>
22
1
 
23
- </div>
2
+ <!-- Paths list -->
3
+ <h4>Requests</h4>
4
+ <div class='grid'>
5
+ <% SafetyCone.paths.each do |cone, options| %>
6
+ <%= options[:name] %>
7
+
8
+ <span class="chip status-<%= status(cone) %>">
9
+ <%= status(cone) %>
10
+ </span>
11
+
12
+ <%= link_to 'edit', edit_path_path(cone), class: 'waves-effect waves-light btn' %>
13
+ <% end %>
14
+ </div>
15
+
16
+ <!-- Features list -->
17
+ <h4>Features</h4>
18
+ <div class='grid'>
19
+ <% SafetyCone.features.each_with_index do |feature, index| %>
20
+ <%= feature[:name] %>
21
+
22
+ <% if feature_status(feature[:feature]) %>
23
+
24
+ <div class="chip status">on</div>
25
+
26
+ <%= button_to 'Block', feature_path(index, params: { state: 0 }),
27
+ method: :patch, class: 'waves-effect waves-light btn expand red'%>
28
+ <% else %>
29
+ <div class="chip status-block">off</div>
30
+
31
+ <%= button_to 'Unblock', feature_path(index, params: { state: 1 }),
32
+ method: :patch, class: 'waves-effect waves-light btn expand'%>
33
+ <% end %>
34
+ <%end%>
24
35
  </div>
@@ -0,0 +1,30 @@
1
+ <div class='grid'>
2
+ <div class='card col'>
3
+ <h6 class="center"><%= @path.name %></h6>
4
+ <%= form_for :path, url: path_path(@path.key), method: :PUT do |form| %>
5
+ <div class='form'>
6
+ <div class='input-field'>
7
+ <%= form.text_field :message %>
8
+ <%= form.label :message, 'Message', class: 'input-label'%>
9
+ </div>
10
+
11
+ <div class='input-field'>
12
+ <%= form.radio_button :type, 'notice' %>
13
+ <%= form.label :type_notice, 'Notice' %>
14
+
15
+ <%= form.radio_button :type, 'block' %>
16
+ <%= form.label :type_block, 'Block' %>
17
+
18
+ <%= form.radio_button :type, 'disabled' %>
19
+ <%= form.label :type_disabled, 'Disable this Cone' %>
20
+ </div>
21
+
22
+ <div class='input-field'>
23
+ <%= form.submit 'save', class: 'waves-effect waves-light btn' %>
24
+ <%= link_to 'cancel', cones_path, class: 'waves-effect waves-light btn grey lighten-1' %>
25
+ </div>
26
+ </div>
27
+ <% end %>
28
+ </div>
29
+ </div>
30
+
data/config/routes.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  SafetyCone::Engine.routes.draw do
2
- root to: 'cones#index'
3
- resources :cones, only: [:index, :edit, :update]
2
+ root to: 'cones#index'
3
+
4
+ resources :cones, only: [:index]
5
+ resources :paths, only: [:edit, :update]
6
+ resources :features, only: [:update]
4
7
  end
data/lib/safety_cone.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'safety_cone/engine'
2
2
  require 'safety_cone/configuration'
3
3
  require 'safety_cone/filter'
4
- require 'safety_cone/view_helper'
4
+ require 'safety_cone/view_helpers'
5
5
 
6
6
  module SafetyCone
7
7
  extend Configuration
@@ -1,9 +1,7 @@
1
1
  module SafetyCone
2
2
  # Module for configuring safety measures
3
3
  module Configuration
4
- VALID_OPTION_KEYS = %i[method controller action name].freeze
5
-
6
- attr_accessor :cones, :options, :redis, :auth
4
+ attr_accessor :options, :redis, :auth, :paths, :features
7
5
 
8
6
  # Method add a route or method to be managed by safety cone
9
7
  def add(options = {})
@@ -11,7 +9,12 @@ module SafetyCone
11
9
 
12
10
  raise(ArgumentError, 'Mandatory param :name missing') unless options[:name]
13
11
 
14
- cones[make_key] = options
12
+ if options[:feature]
13
+ features << options
14
+ SafetyCone::ViewHelpers.add_method(options[:feature])
15
+ else
16
+ paths[make_key] = options
17
+ end
15
18
  end
16
19
 
17
20
  # Method to generate a key from the options
@@ -28,7 +31,8 @@ module SafetyCone
28
31
 
29
32
  # Configuration method for Rails initializer
30
33
  def configure
31
- self.cones = {}
34
+ self.paths = {}
35
+ self.features = []
32
36
  self.auth = { username: nil, password: nil }
33
37
 
34
38
  yield self
@@ -2,13 +2,13 @@ module SafetyCone
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace SafetyCone
4
4
 
5
- initializer "refinery.assets.precompile" do |app|
5
+ initializer 'refinery.assets.precompile' do |app|
6
6
  app.config.assets.precompile += %w(safety_cone/logo.png)
7
7
  end
8
8
 
9
9
  config.generators do |g|
10
- g.test_framework :rspec, :fixture => false
11
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
10
+ g.test_framework :rspec, fixture: false
11
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
12
12
  g.assets false
13
13
  g.helper false
14
14
  end
@@ -24,42 +24,42 @@ module SafetyCone
24
24
 
25
25
  private
26
26
 
27
- # Fetches a configuration based on current request
28
- def fetch_cone
29
- cones = SafetyCone.cones
27
+ # Fetches a configuration based on current request
28
+ def fetch_cone
29
+ paths = SafetyCone.paths
30
30
 
31
- if cone = cones[request_action]
32
- key = request_action
33
- elsif cone = cones[request_method]
34
- key = request_method
35
- else
36
- return false
37
- end
31
+ if path = paths[request_action]
32
+ key = request_action
33
+ elsif cone = paths[request_method]
34
+ key = request_method
35
+ else
36
+ return false
37
+ end
38
38
 
39
- cone = Cone.new(key, cone)
40
- cone.fetch
39
+ path = Path.new(key, path)
40
+ path.fetch
41
41
 
42
- %w[notice block].include?(cone.type) ? cone : false
43
- end
42
+ %w[notice block].include?(path.type) ? path : false
43
+ end
44
44
 
45
- # Method to redirect a request
46
- def safety_redirect
47
- request.env['HTTP_REFERER'] || root_path
48
- end
45
+ # Method to redirect a request
46
+ def safety_redirect
47
+ request.env['HTTP_REFERER'] || root_path
48
+ end
49
49
 
50
- # Returns type of notice
51
- def notice_type(type)
52
- type == 'notice' ? 'notice' : 'alert'
53
- end
50
+ # Returns type of notice
51
+ def notice_type(type)
52
+ type == 'notice' ? 'notice' : 'alert'
53
+ end
54
54
 
55
- # Returns the current request action as a symbol
56
- def request_method
57
- request.method.to_sym
58
- end
55
+ # Returns the current request action as a symbol
56
+ def request_method
57
+ request.method.to_sym
58
+ end
59
59
 
60
- # Returns the current controller_action as a symbol
61
- def request_action
62
- "#{controller_name}_#{action_name}".to_sym
63
- end
60
+ # Returns the current controller_action as a symbol
61
+ def request_action
62
+ "#{controller_name}_#{action_name}".to_sym
63
+ end
64
64
  end
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module SafetyCone
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -0,0 +1,29 @@
1
+ module SafetyCone
2
+ # Module for Filtering requests and raise notices
3
+ # and take measures
4
+ module ViewHelpers
5
+ def safetycone_notice
6
+ flash[:safetycone_notice]
7
+ end
8
+
9
+ def safetycone_alert
10
+ flash[:safetycone_alert]
11
+ end
12
+
13
+ def feature?(name)
14
+ redis = SafetyCone.redis
15
+ redis_key = "safety::cone::#{name}"
16
+ value = redis.get(redis_key)
17
+
18
+ return true unless value
19
+
20
+ value == '1'
21
+ end
22
+
23
+ def self.add_method(name)
24
+ define_method("#{name}?") { feature?(name) }
25
+ end
26
+ end
27
+ end
28
+
29
+ ActionView::Base.send :include, SafetyCone::ViewHelpers
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safety_cone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Boost
7
8
  - Edwin Rozario
8
- - Yar Htut
9
+ - yhtut
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2017-10-24 00:00:00.000000000 Z
13
+ date: 2017-11-16 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rails
@@ -173,9 +174,10 @@ dependencies:
173
174
  version: 2.4.3
174
175
  description: |-
175
176
  At times we would want to block certain requests.
176
- SafetyCone allows this to be controller from an interface.
177
+ SafetyCone allows this to be controlled from an interface.
178
+ It also provides a feature flipper for the views.
177
179
  email:
178
- - edwin@boost.co.nz
180
+ - info@boost.co.nz
179
181
  executables: []
180
182
  extensions: []
181
183
  extra_rdoc_files: []
@@ -189,21 +191,22 @@ files:
189
191
  - app/assets/stylesheets/safety_cone/material.css
190
192
  - app/controllers/safety_cone/application_controller.rb
191
193
  - app/controllers/safety_cone/cones_controller.rb
194
+ - app/controllers/safety_cone/features_controller.rb
195
+ - app/controllers/safety_cone/paths_controller.rb
192
196
  - app/helpers/safety_cone/application_helper.rb
193
197
  - app/helpers/safety_cone/cones_helper.rb
194
198
  - app/models/safety_cone/application_record.rb
195
- - app/models/safety_cone/cone.rb
199
+ - app/models/safety_cone/path.rb
196
200
  - app/views/layouts/safety_cone/application.html.erb
197
- - app/views/safety_cone/cones/edit.html.erb
198
201
  - app/views/safety_cone/cones/index.html.erb
199
- - config/environment.rb
202
+ - app/views/safety_cone/paths/edit.html.erb
200
203
  - config/routes.rb
201
204
  - lib/safety_cone.rb
202
205
  - lib/safety_cone/configuration.rb
203
206
  - lib/safety_cone/engine.rb
204
207
  - lib/safety_cone/filter.rb
205
208
  - lib/safety_cone/version.rb
206
- - lib/safety_cone/view_helper.rb
209
+ - lib/safety_cone/view_helpers.rb
207
210
  homepage: https://github.com/boost/safety_cone
208
211
  licenses:
209
212
  - MIT
@@ -1,33 +0,0 @@
1
- <div class="row">
2
- <div class="col s6 offset-s3">
3
- <h6 class="center"><%= @cone.name %></h6>
4
-
5
- <div class="card">
6
- <%= form_for :cone, url: cone_path(@cone.key), method: :PUT do |form| %>
7
- <div class="row ">
8
- <div class="input-field group col s12">
9
- <%= form.text_field :message %>
10
- <%= form.label :message, 'Message', class: 'input-label'%>
11
- </div>
12
-
13
- <div class="input-field col s12">
14
- <%= form.radio_button :type, 'notice' %>
15
- <%= form.label :type_notice, 'Notice' %>
16
-
17
- <%= form.radio_button :type, 'block' %>
18
- <%= form.label :type_block, 'Block' %>
19
-
20
- <%= form.radio_button :type, 'disabled' %>
21
- <%= form.label :type_disabled, 'Disable this Cone' %>
22
- </div>
23
-
24
- <div class="input-field col s12">
25
- <%= form.submit 'save', class: 'waves-effect waves-light btn' %>
26
- <%= link_to 'cancel', cones_path, class: 'waves-effect waves-light btn grey lighten-1' %>
27
- </div>
28
- </div>
29
- <% end %>
30
- </div>
31
-
32
- </div>
33
- </div>
File without changes
@@ -1,15 +0,0 @@
1
- module SafetyCone
2
- # Module for Filtering requests and raise notices
3
- # and take measures
4
- module Helper
5
- def safetycone_notice
6
- flash[:safetycone_notice]
7
- end
8
-
9
- def safetycone_alert
10
- flash[:safetycone_alert]
11
- end
12
- end
13
- end
14
-
15
- ActionView::Base.send :include, SafetyCone::Helper