feature_gate 0.1.9 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3c01ea6a2c8370a2e6cd7824ed5204df6582c33
4
- data.tar.gz: 3d00f3bff117db908f48532353aa2ecc022837e0
3
+ metadata.gz: 08bf6d98804827f7f661d9f14d87f78788a8774b
4
+ data.tar.gz: 2a86f93c61108519a9363bd81c423fc85a9eb08d
5
5
  SHA512:
6
- metadata.gz: 6a7affda7d87ccf825d96b66d274b6b8f51bf108c29d33f1e31b17b743809360974baa77bf1f6ce1d48862c891394149bcae5f2b25056e9c011f2a5ef4945e43
7
- data.tar.gz: 308e16eeac356c2a0b2ebcc3b43d81b9c9bf0e4bb1ffbaf4725c8d82f99bfb952934f389c8a8b76666feb3b41eb1c95c5c1213de31b658e7a02c8e4f79481c94
6
+ metadata.gz: 71059b7b798d94b690c39aba6b569b391788261b11e896c31e58b2e18dff28a5a183881bc2b0dc18d209e087362a7376c3b93a6c4cf2b3a12901c0e5b019a266
7
+ data.tar.gz: f1e22781451d42d3d88107169acf6c03da857de99981981d342f62aec111b0ed8396937690f7fd8aee99a19e08a1306bcb3d3b075c4ac33f628146b7452ecb9b
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # feature_gate
2
2
 
3
- A gem to help toggle features on and off in Rails applications without having to re-deploy.
3
+ A gem to help manage toggling features on and off in Rails applications without having to re-deploy. Includes a preconfigured page for gate management and an executable for feature gate code cleanup in your codebase after a feature has been deployed.
4
4
 
5
5
  ## Installation
6
6
 
@@ -34,13 +34,15 @@ Add `config/initializers/feature_gate.rb`
34
34
 
35
35
  All gates are closed by default, meaning the features you gate will be hidden until you toggle the gates open.
36
36
 
37
- In view files (comment in `end` is optional and is just to make it removable via the cleaner):
37
+ To gate a part of a page:
38
+ In view files (add `# gate-name` after `end` to allow the cleaner executable to remove this line when cleaning the gate out of the files):
38
39
 
39
40
  <% FeatureGate::Manager.gate('gate-name') do %>
40
41
  <h1>This is my gated content</h1>
41
42
  <p>I am not seen if the gate is on</p>
42
43
  <% end # gate-name %>
43
44
 
45
+ To gate an entire page:
44
46
  In controller actions:
45
47
 
46
48
  def index
@@ -49,9 +51,10 @@ In controller actions:
49
51
 
50
52
  ### Managing gates
51
53
 
52
- <img src="http://i.imgur.com/p4lMIfo.png">
54
+ <img src="http://i.imgur.com/qo8zESV.png">
55
+
56
+ Go to `/feature_gate` for a preconfigured page to manage your gates. It lists all your gates and gives you the ability to toggle them open or closed. Additionally, it lists all your "stale" gates - gates that have not been touched in 1 month (timeframe is configurable, see under Optional Configurations) and allows you to delete them from your database *if* it is no longer used in your codebase (this check is done automatically when you try to delete a gate).
53
57
 
54
- Go to `/feature_gate` for a preconfigured page that lists all your gates and give you the ability to toggle them open or close.
55
58
 
56
59
  To limit accessibility to this page, define `feature_gate_control_allowed?` in `application_controller.rb`. If the method is not defined, `/feature_gate` will be accessible to <em>all</em> users.
57
60
 
@@ -86,3 +89,7 @@ To see the names of all closed gates:
86
89
  To see the names of all stale gates:
87
90
 
88
91
  FeatureGate::Manager.stale_gates
92
+
93
+ To safely delete a gate (only deletes if not used in codebase):
94
+
95
+ FeatureGate::Manager.destroy!('gate-name')
@@ -13,10 +13,22 @@ module FeatureGate
13
13
  gate = FeatureGate::GatedFeature.find(params[:id])
14
14
  if params[:gated] == 'true'
15
15
  gate.gate_feature!
16
- flash[:notice] = 'Feature has been gated'
16
+ flash[:notice] = "#{gate.name} has been gated"
17
17
  else
18
18
  gate.deploy_feature!
19
- flash[:success] = 'Feature is live!'
19
+ flash[:success] = "#{gate.name} is live!"
20
+ end
21
+
22
+ redirect_to gated_features_path
23
+ end
24
+
25
+ def destroy
26
+ gate = FeatureGate::GatedFeature.find(params[:id])
27
+ if gate.destroyable?
28
+ gate.destroy!
29
+ flash[:success] = "#{gate.name} has been deleted"
30
+ else
31
+ flash[:error] = "#{gate.name} is currently being used in the codebase, execute `feature_gate_cleaner #{gate.name}` in the terminal to remove all references to #{gate.name}"
20
32
  end
21
33
 
22
34
  redirect_to gated_features_path
@@ -26,5 +26,18 @@ module FeatureGate
26
26
  'opened'
27
27
  end
28
28
  end
29
+
30
+ def destroyable?
31
+ regex = /FeatureGate::Manager.gate(\(|\s)('|")#{name}('|")|FeatureGate::Manager.gate_page(\(|\s)('|")#{name}('|")/
32
+ files = Dir["#{Dir.pwd}/app/views/**/*.html.erb"] + Dir["#{Dir.pwd}/app/controllers/**/*.rb"]
33
+
34
+ files.each do |file|
35
+ f = File.new(file)
36
+ text = f.read
37
+ return false if text =~ regex
38
+ end
39
+
40
+ true
41
+ end
29
42
  end
30
43
  end
@@ -35,5 +35,15 @@ module FeatureGate
35
35
  gated_feature = GatedFeature.find_by_name!(name)
36
36
  gated_feature.gate_feature!
37
37
  end
38
+
39
+ def self.destroy!(name)
40
+ gate = GatedFeature.find_by_name!(name)
41
+ if gate.destroyable?
42
+ gate.destroy!
43
+ puts "#{gate.name} destroyed"
44
+ else
45
+ puts "#{gate.name} is currently being used in the codebase, execute `feature_gate_cleaner #{gate.name}` in the terminal to remove all references to #{gate.name}"
46
+ end
47
+ end
38
48
  end
39
49
  end
@@ -52,6 +52,7 @@
52
52
  <th>Gate name</th>
53
53
  <th>Status</th>
54
54
  <th>Last updated at</th>
55
+ <th>Action</th>
55
56
  </tr>
56
57
 
57
58
  <% @stale_gates.each do |gate| %>
@@ -59,6 +60,7 @@
59
60
  <td><%= gate.name %></td>
60
61
  <td><%= gate.status %></td>
61
62
  <td><%= gate.updated_at.strftime('%F') %></td>
63
+ <td><%= link_to 'Destroy', gated_feature_path(gate), method: :delete, data: { confirm: "Destroying #{gate.name}, are you sure?" } %></td>
62
64
  </tr>
63
65
  <% end %>
64
66
  </table>
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  FeatureGate::Engine.routes.draw do
2
- resources :gated_features, only: [:index, :update]
2
+ resources :gated_features, only: [:index, :update, :destroy]
3
3
  get '/' => 'gated_features#index'
4
4
  end
@@ -1,3 +1,3 @@
1
1
  module FeatureGate
2
- VERSION = '0.1.9'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feature_gate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiffany Huang