benchdog-rails 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d0cf59b5b9e58444ba5a95a179bcb90aa937ce262977aefcce27ee4b8e29b5e4
4
+ data.tar.gz: 30631e8bfdbcc7e9e6a785646a31aa4dbdc62f32f249222379bbbb2ee0d01050
5
+ SHA512:
6
+ metadata.gz: f2c85b171e932dd1de7403a4d4d5cad95a9f91b29b2430975366541d5bed1e501161a0149b5290d614d8101de6e260e517d02d31539fd4c3fb2c4cbadfe6e0aa
7
+ data.tar.gz: 143bb1421c38a462811249f272bfb819e1652fe2a9ee4ede6171f2f4cab931b46cce3f1b1e1ed06029b6236b9a44016145d6ef8e202de23a7d461b7eb05bb857
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joe Gaudet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # benchdog-rails
2
+
3
+ [Benchdog](https://joegaudet.com/benchdog/) for Rails 7.1 and later. The gem has:
4
+
5
+ - `Benchdog::Rails::ActiveRecordStore`: the flags and the audit log in two tables.
6
+ - `Benchdog::Rails::Engine`: the dashboard and the admin API at one mount path.
7
+ - `Benchdog::Rails::Controller`: a concern that gives the actor of the request to Benchdog.
8
+ - `benchdog_payload_tag`: a view helper for the browser client.
9
+ - `rails generate benchdog:install`: the migration for the two tables.
10
+
11
+ ## Install
12
+
13
+ ```ruby
14
+ # Gemfile
15
+ gem "benchdog"
16
+ gem "benchdog-rails"
17
+ ```
18
+
19
+ ```bash
20
+ bin/rails generate benchdog:install
21
+ bin/rails db:migrate
22
+ ```
23
+
24
+ ## Configure
25
+
26
+ ```ruby
27
+ # config/initializers/benchdog.rb
28
+ Benchdog::Rails.configure do |config|
29
+ config.store = Benchdog::Rails::ActiveRecordStore.new
30
+ config.environments = [{ name: "staging", promotes_to: "production" }, { name: "production", protected: true }]
31
+ config.environment = ENV.fetch("BENCHDOG_ENVIRONMENT", "staging") # one of the environments; default: Rails.env
32
+ config.authenticate = lambda { |env|
33
+ user = env["warden"]&.user
34
+ user && { "id" => user.id.to_s, "name" => user.name }
35
+ }
36
+ config.role_for = ->(user, _environment) { User.find(user["id"]).admin? ? "admin" : "viewer" }
37
+ config.groups = { "staff" => ->(actor) { actor["id"].start_with?("staff:") } }
38
+ end
39
+ ```
40
+
41
+ The other options are `actor_for`, `cron_secret`, `references` and `audience`, the same as the
42
+ Express host. `config.environment` is the environment of the app's own client (default:
43
+ `Rails.env`).
44
+
45
+ ```ruby
46
+ # config/routes.rb
47
+ mount Benchdog::Rails::Engine, at: "/benchdog"
48
+ ```
49
+
50
+ The dashboard is at `/benchdog/`, and the admin API is at `/benchdog/api`.
51
+
52
+ ## Use
53
+
54
+ ```ruby
55
+ class ApplicationController < ActionController::Base
56
+ include Benchdog::Rails::Controller
57
+
58
+ private
59
+
60
+ # Optional. The default is "user:<id>" of current_user.
61
+ def benchdog_actor = current_account && { "id" => "account:#{current_account.id}" }
62
+ end
63
+ ```
64
+
65
+ ```erb
66
+ <% if benchdog_enabled?("new-checkout") %>...<% end %>
67
+ <%= benchdog_payload_tag %>
68
+ ```
69
+
70
+ `benchdog_payload_tag` writes the flags with the `client` tag for the actor, for `readPayload()` of
71
+ `@benchdog-ts/client`. Each request loads one snapshot, on the first use.
72
+
73
+ ## Limits
74
+
75
+ - The approvals and the change feed of `GET /stream` are in the memory of each process.
76
+ - The gem includes the dashboard. `config.dashboard_dir` serves another build.
77
+
78
+ ## Checks
79
+
80
+ ```bash
81
+ bundle install
82
+ bundle exec rubocop
83
+ bundle exec steep check
84
+ bundle exec rspec
85
+ ```
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Benchdog::Rails::Engine.routes.draw do
4
+ mount ->(env) { Benchdog::Rails.admin_api.call(env) }, at: "/api"
5
+ mount Benchdog::Rails::Dashboard.new, at: "/"
6
+ end