Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register policies directories for Rails 8 code statistics #833

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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