Skip to content

Commit fc3a8f8

Browse files
authored
Merge pull request #44 from cardmagic/fix/defer-active-record-load
Load the record class when Active Record loads
2 parents 89f34ed + af35b02 commit fc3a8f8

12 files changed

Lines changed: 131 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 0.13.3 - 2026-08-18
4+
5+
- Stop loading `ActiveRecord::Base` when the gem is required. The engine now
6+
loads `SolidObjects::Record` from an `ActiveSupport.on_load(:active_record)`
7+
hook, so a host application keeps the normal timing of its own
8+
`on_load(:active_record)` and `on_load(:active_record_encryption)` hooks. An
9+
application that assigns its Active Record encryption keys in
10+
`config/initializers` no longer loses them.
11+
- Apply the configured `connects_to` in the record class body, so the
12+
connection follows the class through a development reload.
13+
314
## 0.13.2 - 2026-08-17
415

516
- Accept a `key:` on `schedule`, naming a reminder for the item it is waiting

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
solid_objects (0.13.2)
4+
solid_objects (0.13.3)
55
actioncable (>= 8.0)
66
actionpack (>= 8.0)
77
actionview (>= 8.0)
@@ -384,7 +384,7 @@ CHECKSUMS
384384
rubocop-rails-omakase (1.1.0) sha256=2af73ac8ee5852de2919abbd2618af9c15c19b512c4cfc1f9a5d3b6ef009109d
385385
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
386386
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
387-
solid_objects (0.13.2)
387+
solid_objects (0.13.3)
388388
sqlite3 (2.9.5-aarch64-linux-gnu) sha256=78075b6337d3d182c6d2b4691049ed45cd220826160c9ea18946bf6a1de200dc
389389
sqlite3 (2.9.5-aarch64-linux-musl) sha256=18c801185deb4adc01ddb281e8f672a39e3d1729979ca91e39439cd3eac0402d
390390
sqlite3 (2.9.5-arm-linux-gnu) sha256=1bdfca0c7d63998c60b0f4a8e3c8df2d33800ccc4abd2d612eddbbbc92a4c48b

app/models/solid_objects/record.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ def configure_connection
1313
connects_to(**connection_configuration)
1414
end
1515
end
16+
17+
configure_connection
1618
end
1719
end

lib/solid_objects/engine.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# rbs_inline: enabled
22

3-
require_relative "../../app/models/solid_objects/record"
4-
53
module SolidObjects
64
class Engine < ::Rails::Engine
5+
RECORD_PATH = File.expand_path("../../app/models/solid_objects/record.rb", __dir__)
6+
77
isolate_namespace SolidObjects
88

99
config.generators do |generators|
@@ -16,7 +16,9 @@ class Engine < ::Rails::Engine
1616
end
1717

1818
initializer "solid_objects.database", after: :load_config_initializers do
19-
SolidObjects::Record.configure_connection
19+
ActiveSupport.on_load(:active_record) do
20+
require RECORD_PATH
21+
end
2022
end
2123

2224
initializer "solid_objects.helpers" do

lib/solid_objects/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# rbs_inline: enabled
22

33
module SolidObjects
4-
VERSION = "0.13.2"
4+
VERSION = "0.13.3"
55
end

sig/generated/lib/solid_objects/engine.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module SolidObjects
44
class Engine < ::Rails::Engine
5+
RECORD_PATH: untyped
6+
57
include SolidObjects::ActorHelper
68
end
79
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
Rails.application.config.active_record.encryption.primary_key =
4+
"solid-objects-dummy-primary-key"
5+
Rails.application.config.active_record.encryption.deterministic_key =
6+
"solid-objects-dummy-deterministic-key"
7+
Rails.application.config.active_record.encryption.key_derivation_salt =
8+
"solid-objects-dummy-key-derivation-salt"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
if ENV["SOLID_OBJECTS_DUMMY_CONNECTS_TO"]
4+
SolidObjects.configure do |config|
5+
config.connects_to = { database: { writing: :primary } }
6+
end
7+
end

test/dummy/connects_to_check.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
ENV["RAILS_ENV"] = "test"
4+
ENV["SOLID_OBJECTS_DUMMY_CONNECTS_TO"] = "1"
5+
6+
require_relative "config/environment"
7+
8+
Rails.application.eager_load!
9+
10+
puts ActiveRecord::Base.connection_handler.connection_pool_names.sort.join(" ")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
ENV["RAILS_ENV"] = "test"
4+
5+
require_relative "config/environment"
6+
7+
puts ActiveRecord::Encryption.config.primary_key

0 commit comments

Comments
 (0)