strongroom-rails 0.5.1 → 0.6.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
  SHA256:
3
- metadata.gz: b88bdc97033bd0b6f93bbe7cdadc65d7f5874d405dd01cc777a44c21c7887913
4
- data.tar.gz: c19bf601209285252a93fce614c3c1d21d9c75ab440113dc392495a3b0aa180d
3
+ metadata.gz: 9874214d06ec5ee79f4b5dbe6aa37235c93451f0d6cd0a467eaea5cda6ea07e3
4
+ data.tar.gz: 8beaca6f9106e1659c927a7d6996fc33222de15d240081d6919fcd4c90bdaba6
5
5
  SHA512:
6
- metadata.gz: ad054bbcc04975ba97dee7585dfffe1aaae660090b25e953bbe3e86ee6240244b2afe8bb0dad7401ecac15b21e680c30638d9dfb5fd336cf0585645ff922593e
7
- data.tar.gz: 578c236380ea2ab5a5cef2bcc82c26ac2c6dc8b7579a083cd67be6c8e44cc5fc107dabfe121f356fa00164de8ce32ecc3cb745ab91c957b8ea457147044a9ac8
6
+ metadata.gz: 37a61e6319cde2de30a01b6f0b1e87b4e78a3772bd8631cca99f3895db15b70d6d04b131deb59652e7f6009440dc4bf8e0aef07be054b0ace04bb2a6d8d7a40b
7
+ data.tar.gz: 636f1b27d3b89102f6b5b619dae3bb49ae44c4c24ee14c4466e279785689e3a92fdff19ff624e1de038289165f155cb76c700f2709a81728a3b1cedb55a555b5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.5.1...strongroom-rails-v0.6.0) (2026-11-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * **strongroom-rails:** accept a lambda for Account model: so building the registry loads no model at boot ([#10](https://github.com/seuros/strongroom/issues/10)) ([99a71c4](https://github.com/seuros/strongroom/commit/99a71c428c5b142eeaccb60c205c67f961ef9a64))
9
+
3
10
  ## [0.5.1](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.5.0...strongroom-rails-v0.5.1) (2026-11-08)
4
11
 
5
12
 
data/README.md CHANGED
@@ -53,10 +53,6 @@ Configure existing Strongroom org/app IDs, not Rails IDs.
53
53
  Use separate namespaces/bindings for users and admins; naming a namespace
54
54
  `admin` does not implement MFA or authorize an admin migration.
55
55
 
56
- Build the registry in a Rails initializer's `to_prepare` block so reloadable
57
- model classes are resolved afresh. This example deliberately leaves your
58
- binding storage and eligibility policy explicit:
59
-
60
56
  ```ruby
61
57
  Rails.application.config.to_prepare do
62
58
  client = Strongroom::Client.new(
@@ -65,7 +61,7 @@ Rails.application.config.to_prepare do
65
61
  )
66
62
 
67
63
  users = Strongroom::Rails::Account.new(
68
- client: client, table: "users", model: User,
64
+ client: client, table: "users", model: -> { User },
69
65
  # Your store must uniquely bind issuer + namespace + org + app + kernel
70
66
  # user_id to a pre-existing local record. Missing binding returns nil.
71
67
  resolve: ->(subject) { YourTrustedBindingStore.lookup(subject)&.record },
@@ -104,7 +100,8 @@ authenticate (for example an asset build without credentials) can opt out with
104
100
 
105
101
  Add additional `Account` objects to the registry for other approved namespaces.
106
102
  At most 16 are supported; names, tables and same-issuer audiences must be distinct.
107
- Pass actual model classes, never class names from parameters/configuration.
103
+ Pass a model class or a lambda returning one, never class names from
104
+ parameters/configuration. A lambda is checked against `table:` when first called.
108
105
  `register` defaults false; `register: true` needs a client configured with
109
106
  `service_endpoint:` and `service_key:` and enables `register_account` and
110
107
  `issue_verification` on the account; `issue_recovery`, `events`, `suspend`,
@@ -306,7 +303,7 @@ client = Strongroom::Client.new(
306
303
  org_id: ENV.fetch("STRONGROOM_USERS_ORG_ID"), app_id: ENV.fetch("STRONGROOM_USERS_APP_ID"),
307
304
  service_endpoint: ENV.fetch("STRONGROOM_SERVICE_ENDPOINT"), service_key: ENV.fetch("STRONGROOM_USERS_SERVICE_KEY")
308
305
  )
309
- users = Strongroom::Rails::Account.new(client: client, table: "users", model: User, register: true,
306
+ users = Strongroom::Rails::Account.new(client: client, table: "users", model: -> { User }, register: true,
310
307
  resolve: ..., eligible: ...)
311
308
 
312
309
  registration = users.register_account(external_id: user.id.to_s, identity: params[:email],
@@ -3,7 +3,17 @@
3
3
  module Strongroom
4
4
  module Rails
5
5
  class Account
6
- attr_reader :client, :table, :model, :register, :cookie_name
6
+ attr_reader :client, :table, :register, :cookie_name
7
+
8
+ def self.checked_model(model, table)
9
+ unless model.is_a?(Class) && model.respond_to?(:table_name)
10
+ raise ConfigurationError, "model must be a class responding to table_name, not #{model.inspect}"
11
+ end
12
+ unless model.table_name == table
13
+ raise ConfigurationError, "#{model}.table_name is #{model.table_name.inspect}, not #{table.inspect}"
14
+ end
15
+ model
16
+ end
7
17
 
8
18
  def initialize(client:, table:, model:, resolve:, eligible:, register: false)
9
19
  raise ConfigurationError, "client must be a Strongroom::Client" unless client.is_a?(Client)
@@ -11,11 +21,10 @@ module Strongroom
11
21
  raise ConfigurationError, "table must be a lowercase SQL identifier of at most 63 characters"
12
22
  end
13
23
  raise ConfigurationError, "table #{table} is a PostgreSQL system name (pg_*)" if table.start_with?("pg_")
14
- unless model.is_a?(Class) && model.respond_to?(:table_name)
15
- raise ConfigurationError, "model must be a class responding to table_name, not #{model.inspect}"
16
- end
17
- unless model.table_name == table
18
- raise ConfigurationError, "#{model}.table_name is #{model.table_name.inspect}, not #{table.inspect}"
24
+ if model.is_a?(Module) || !model.respond_to?(:call)
25
+ self.class.checked_model(model, table)
26
+ elsif !model.respond_to?(:arity) || model.arity.positive?
27
+ raise ConfigurationError, "model callable must take no arguments and return the model class"
19
28
  end
20
29
  raise ConfigurationError, "resolve must be callable (subject -> record or nil)" unless resolve.respond_to?(:call)
21
30
  raise ConfigurationError, "eligible must be callable (record -> true)" unless eligible.respond_to?(:call)
@@ -93,6 +102,8 @@ module Strongroom
93
102
  raise Unavailable, "local principal lookup unavailable", cause: nil
94
103
  end
95
104
 
105
+ def model = @model.is_a?(Module) ? @model : self.class.checked_model(@model.call, table)
106
+
96
107
  private
97
108
 
98
109
  def registering!
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Strongroom
4
4
  module Rails
5
- VERSION = "0.5.1" # x-release-please-version
5
+ VERSION = "0.6.0" # x-release-please-version
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strongroom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seuros