Skip to content

Commit

Permalink
Create a spring_booted ActiveSupport load hook
Browse files Browse the repository at this point in the history
This load hook is run after the Application has been preloaded. It can be used to set additional paths for the file watcher.

Co-Authored-By: Gannon McGibbon <[email protected]>
  • Loading branch information
andrewn617 and gmcgibbon committed Jul 25, 2024
1 parent c5987d5 commit 2903687
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def preload
watcher.add secrets_path
end
end

ActiveSupport.run_load_hooks(:spring_booted, self)
end

def eager_preload
Expand Down
10 changes: 10 additions & 0 deletions test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,16 @@ def exec_name
test "rails db:system:change" do
assert_success "bin/rails db:system:change --to=sqlite3"
end

test "spring_booted load hook is called when booting the application" do
File.write(app.path("config/initializers/spring_booted.rb"), <<~RUBY)
ActiveSupport.on_load(:spring_booted) do
raise "Argh!"
end
RUBY

assert_failure "bin/rails runner ''", stderr: "Argh!"
end
end
end
end

0 comments on commit 2903687

Please sign in to comment.