8000 Use safe navigation for `pundit_default_policy` (#8530) · activeadmin/activeadmin@006abfc · GitHub
[go: up one dir, main page]

Skip to content

Commit 006abfc

Browse files
authored
Use safe navigation for pundit_default_policy (#8530)
Use the safe navigation operator (`&.`) to streamline the `pundit_default_policy` constantization check, removing the need for a redundant `&&`. This change is now possible as the codebase no longer requires Ruby 2.3 support, which did not yet support safe navigation. The previous implementation was added in commit c93f6f4 to ensure compatibility with older Ruby versions. Also add the safe navigation operator to a subsequent usage of `default_policy_class`
1 parent a19acfb commit 006abfc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/active_admin/pundit_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def scope_collection(collection, action = Auth::READ)
2323
# which means there is no way how to scope other actions
2424
Pundit.policy_scope!(user, namespace(collection))
2525
rescue Pundit::NotDefinedError => e
26-
if default_policy_class && default_policy_class.const_defined?(:Scope)
26+
if default_policy_class&.const_defined?(:Scope)
2727
default_policy_class::Scope.new(user, collection).resolve
2828
else
2929
raise e
@@ -95,7 +95,7 @@ def namespace(object)
9595
end
9696

9797
def default_policy_class
98-
ActiveAdmin.application.pundit_default_policy && ActiveAdmin.application.pundit_default_policy.constantize
98+
ActiveAdmin.application.pundit_default_policy&.constantize
9999
end
100100

101101
def default_policy(subject)

0 commit comments

Comments
 (0)
0