Skip to content

Commit

Permalink
Register policies directories for Rails 8 code statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
javierav committed Oct 9, 2024
1 parent ec75796 commit 62dbd4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Added

- Register policies directories for Rails 8 code statistics (#833)

## 2.4.0 (2024-08-26)

## Changed
Expand Down
1 change: 1 addition & 0 deletions lib/pundit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require "pundit/context"
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 62dbd4f

Please sign in to comment.