Skip to content

Commit

Permalink
Ensure roles are registered when application loads
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmypoulsen committed Dec 16, 2024
1 parent f54c536 commit b9d7ee3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/pundit_role_play/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class Railtie < Rails::Railtie
Rails.application.config.eager_load_paths << Rails.root.join("app", "roles")
end

initializer "pundit_role_play.eager_load_roles" do
Rails.application.config.to_prepare do
# Force Zeitwerk to load all role classes
Dir[Rails.root.join("app/roles/**/*.rb")].each { |file| require_dependency file }
end
end

initializer "pundit_role_play.extend_active_record" do
ActiveSupport.on_load(:active_record) do
extend PunditRolePlay::Adapter::ActiveRecord
Expand Down

0 comments on commit b9d7ee3

Please sign in to comment.