flipside 0.2.0 → 0.2.1
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +23 -4
- data/lib/flipside/config/settings.rb +7 -0
- data/lib/flipside/version.rb +1 -1
- data/lib/flipside/views/index.erb +17 -12
- data/lib/flipside.rb +13 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e49af6fc8d31128f0e88089ad6d46ce1745a223a68c4f5e4f2e5353f99091073
|
4
|
+
data.tar.gz: cb1547b1c3892b363830aa5f75375998092b90f150e6a275b3224051b6eb3b19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc95be97c95f5c6285d4eb57e6b378b47277d61e43f6606eb44bf9c9c6f914a2b6019c4a143c8b9a5058c64eac6ea0f4cffbecf7138ad3836ca0dcb196515c22
|
7
|
+
data.tar.gz: fb5262d598dea36dd87e7c987ae1d263500b2bc7e39882d7da5a119a6c11aab009821d7981732a442176985054900355e6bcf2b8d2b0fa68eab99e03a6469337
|
data/CHANGELOG.md
CHANGED
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
|
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
|
-
|
109
|
-
|
109
|
+

|
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
|
+

|
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.
|
data/lib/flipside/version.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
-
<div class="
|
2
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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.
|
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-
|
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
|