flipside 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 982b83a0163d681b2b82a9d2e6d8315044e28b74c7fa437f0b9b267f2e409a90
4
- data.tar.gz: fc0cabac07632fe04647b28af3cecf2fc5cd8400ca5c33107831812f0551ad65
3
+ metadata.gz: e49af6fc8d31128f0e88089ad6d46ce1745a223a68c4f5e4f2e5353f99091073
4
+ data.tar.gz: cb1547b1c3892b363830aa5f75375998092b90f150e6a275b3224051b6eb3b19
5
5
  SHA512:
6
- metadata.gz: a076c81b783ed62ae7975373048c5a0cb4b3575971840c7f190ba4dc2a2cbd9ef9d3a5524e1b4375d0d8712f77317fea4f0a9dbd4d4547290c1a75483d8739da
7
- data.tar.gz: 887476b87ce17f6069d9b6dfef90e693399e43b16877aae67cc636aa0008b288c6d49ef19e66ecf76ad428bc75df04ce7878f00ab0d8cecb18e29321c4b390a5
6
+ metadata.gz: cc95be97c95f5c6285d4eb57e6b378b47277d61e43f6606eb44bf9c9c6f914a2b6019c4a143c8b9a5058c64eac6ea0f4cffbecf7138ad3836ca0dcb196515c22
7
+ data.tar.gz: fb5262d598dea36dd87e7c987ae1d263500b2bc7e39882d7da5a119a6c11aab009821d7981732a442176985054900355e6bcf2b8d2b0fa68eab99e03a6469337
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.2.1] - 2025-01-30
2
+
3
+ - Option to create missing features
4
+ - Option to set link back to main application
5
+
1
6
  ## [0.2.0] - 2025-01-29
2
7
 
3
8
  - Support checking multiple objects at once
data/README.md CHANGED
@@ -58,7 +58,7 @@ Flipside::Feature.create(
58
58
  )
59
59
  ```
60
60
 
61
- Features can be enabled for a certain record, typically a certain record or organization. This records are called entities. To enable a feature for a given record use.
61
+ Features can be enabled for a certain record, typically a certain user or organization. This records are called entities. To enable a feature for a given record use `.add_entity`:
62
62
  ```ruby
63
63
  user = User.first
64
64
  Flipside.enabled? user # => false
@@ -67,7 +67,7 @@ Flipside.enabled? user # => true
67
67
  ```
68
68
 
69
69
  Features can be enabled for records responding true to a certain method. This is called a "role". Given that User records have an admin? method. A feature can then be enabled
70
- for all users how are admins.
70
+ for all users how are admins, using the `.add_role` method:
71
71
  ```ruby
72
72
  user1 = User.new(admin: false)
73
73
  user2 = User.new(admin: true)
@@ -104,13 +104,32 @@ Flipside comes with a sinatra web ui to mange feature flags. To mount this sinat
104
104
  ```ruby
105
105
  mount Flipside::Web, at: '/flipside'
106
106
  ```
107
+ Note: you probably want to wrap this inside a constraints block to provide some authentication.
107
108
 
108
- Note: you also probably want to wrap this inside a constraints block to provide some authentication.
109
-
109
+ ![UI](/features.png)
110
110
 
111
111
 
112
112
  ### Configuration
113
113
 
114
+ Entities can be added to a feature by searching for records and adding them.
115
+ ![Start screen](/add_entity.png)
116
+
117
+ To make this work, some configuration is required. Use the class method `Flipside.register_entity` for this.
118
+ ```ruby
119
+ Flipside.register_entity(
120
+ class_name: "User",
121
+ search_by: :name,
122
+ display_as: :name,
123
+ identified_by: :id
124
+ )
125
+ ```
126
+ Typically this should be configured in an initializer file.
127
+
128
+ The `.register_entity` method should be called once for each class that may be used as feature enablers.
129
+ The `search_by` keyword argument, which may be a symbol or a proc, dictates how records are found from searching in the ui. When a symbol is given, then searches with an exact match on the corresponding attribute are returned. E.g. `User.where(name: query)`.
130
+
131
+ TODO
132
+
114
133
  ## Development
115
134
 
116
135
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests.
@@ -0,0 +1,7 @@
1
+ module Flipside
2
+ module Config
3
+ module Settings
4
+ attr_accessor :ui_back_path, :create_missing_features
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flipside
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -1,15 +1,20 @@
1
- <div class="mt-12 w-3/4 m-auto bg-gray-800 text-slate-400 p-8 pb-24 rounded-lg shadow-lg">
2
- <h1 class="text-3xl text-center font-bold mb-6">Flipside feature flags</h1>
1
+ <div class="m-12">
2
+ <% if Flipside.ui_back_path %>
3
+ <a href="<%= Flipside.ui_back_path %>" class="p-2 rounded-lg text-xl text-slate-300 bg-blue-900 border border-blue-950 hover:bg-blue-800">Back</a>
4
+ <% end %>
5
+ <div class="mt-12 w-3/4 m-auto bg-gray-800 text-slate-400 p-8 pb-24 rounded-lg shadow-lg">
6
+ <h1 class="text-3xl text-center font-bold mb-6">Flipside feature flags</h1>
3
7
 
4
- <div class="mt-12 m-auto">
5
- <ul>
6
- <% features.each do |feature| %>
7
- <li class="border-b border-slate-500 hover:font-semibold">
8
- <a href=<%= feature.href %>>
9
- <%= erb :_feature_item, locals: {feature:} %>
10
- </a>
11
- </li>
12
- <% end %>
13
- </ul>
8
+ <div class="mt-12 m-auto">
9
+ <ul>
10
+ <% features.each do |feature| %>
11
+ <li class="border-b border-slate-500 hover:font-semibold">
12
+ <a href=<%= feature.href %>>
13
+ <%= erb :_feature_item, locals: {feature:} %>
14
+ </a>
15
+ </li>
16
+ <% end %>
17
+ </ul>
18
+ </div>
14
19
  </div>
15
20
  </div>
data/lib/flipside.rb CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  require "flipside/version"
4
4
  require "flipside/web"
5
+ require "flipside/config/settings"
5
6
  require "flipside/config/entities"
6
7
  require "flipside/config/roles"
7
8
  require "models/flipside/feature"
8
9
 
9
10
  module Flipside
11
+ extend Config::Settings
10
12
  extend Config::Entities
11
13
  extend Config::Roles
12
14
 
@@ -52,12 +54,21 @@ module Flipside
52
54
  feature.roles.find_by(id: role_id)&.destroy
53
55
  end
54
56
 
55
- def find_by(name:)
56
- Feature.find_by(name:)
57
+ def find_by(name:, create_on_missing: create_missing_features)
58
+ feature = Feature.find_by(name:)
59
+ feature ||= create_missing(name) if create_on_missing
60
+ feature
57
61
  end
58
62
 
59
63
  def find_by!(name:)
60
64
  find_by(name:) || raise(NoSuchFeauture.new(name))
61
65
  end
66
+
67
+ def create_missing(name)
68
+ trace = caller.find { |trace| !trace.start_with? __FILE__ }
69
+ source, line, _ = trace.split(":")
70
+ source = [source, line].join(":") if line.match?(/\d+/)
71
+ Feature.create(name:, description: "Created from #{source}")
72
+ end
62
73
  end
63
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipside
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sammy Henningsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-29 00:00:00.000000000 Z
11
+ date: 2025-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -103,6 +103,7 @@ files:
103
103
  - lib/flipside/config/registered_entity.rb
104
104
  - lib/flipside/config/registered_role.rb
105
105
  - lib/flipside/config/roles.rb
106
+ - lib/flipside/config/settings.rb
106
107
  - lib/flipside/feature_presenter.rb
107
108
  - lib/flipside/public/index.js
108
109
  - lib/flipside/public/modal_controller.js