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 1, 2024
1 parent ec75796 commit 2ee5756
Show file tree
Hide file tree
Showing 3 changed files with 26 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
21 changes: 21 additions & 0 deletions lib/pundit/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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"

Rails::CodeStatistics.register_directory(
"Policies", Rails.root.join("app/policies").to_s
)

%w[test/policies spec/policies].each do |dir|
path = Rails.root.join(dir)

Rails::CodeStatistics.register_directory("Policies tests", path.to_s, test_directory: true) if path.exist?
end
end
end
end
end

0 comments on commit 2ee5756

Please sign in to comment.