Skip to content

Commit

Permalink
Merge pull request #833 from javierav/rails-stats
Browse files Browse the repository at this point in the history
Register policies directories for Rails 8 code statistics
  • Loading branch information
Burgestrand authored Feb 25, 2025
2 parents cbaa0ab + 8dfc38f commit 5507430
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Add `Pundit::Authorization#pundit_reset!` hook to reset the policy and policy scope cache. (#830)
- Add links to gemspec. (#845)
- Register policies directories for Rails 8 code statistics (#833)

## Changed

Expand Down
1 change: 1 addition & 0 deletions lib/pundit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "pundit/cache_store"
require "pundit/cache_store/null_store"
require "pundit/cache_store/legacy_store"
require "pundit/railtie" if defined?(Rails)

# @api private
# To avoid name clashes with common Error naming when mixing in Pundit,
Expand Down
19 changes: 19 additions & 0 deletions lib/pundit/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Pundit
class Railtie < Rails::Railtie
if Rails.version.to_f >= 8.0
initializer "pundit.stats_directories" do
require "rails/code_statistics"

if Rails.root.join("app/policies").directory?
Rails::CodeStatistics.register_directory("Policies", "app/policies")
end

if Rails.root.join("test/policies").directory?
Rails::CodeStatistics.register_directory("Policy tests", "test/policies", test_directory: true)
end
end
end
end
end

0 comments on commit 5507430

Please sign in to comment.