Skip to content

Use safe navigation for pundit_default_policy #8530

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

Merged
merged 1 commit into from
Nov 2, 2024

Conversation

tagliala
Copy link
Contributor

@tagliala tagliala commented Nov 2, 2024

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.

Copy link

codecov bot commented Nov 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.11%. Comparing base (a19acfb) to head (774c7f4).
Report is 11 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8530   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files         141      141           
  Lines        4076     4076           
=======================================
  Hits         4040     4040           
  Misses         36       36           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tagliala tagliala force-pushed the chore/use-safe-navigation-operator branch from 91ecbe7 to e18c341 Compare November 2, 2024 18:03
Copy link
Member

@javierjulio javierjulio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think there is another instance on line 26 that can be changed too.

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`
@tagliala tagliala force-pushed the chore/use-safe-navigation-operator branch from e18c341 to 774c7f4 Compare November 2, 2024 21:47
tagliala added a commit that referenced this pull request Nov 2, 2024
Replace a logic `&&` with safe navigation operator now that Ruby < 2.3
support is not required anymore

Ref: #8530
tagliala added a commit that referenced this pull request Nov 2, 2024
Replace a logic `&&` with safe navigation operator now that Ruby < 2.3
support is not required anymore

Benchmark (Ruby 3.3.5 x64 / M1 Pro):

```
Comparison (not `nil`):
                  &.: 18787752.0 i/s
                  &&: 17963968.8 i/s - 1.05x  (± 0.00) slower

Comparison (`nil`):
                  &&: 21343215.5 i/s
                  &.: 20910008.5 i/s - 1.02x  (± 0.00) slower
```

Ref: #8530
@tagliala tagliala merged commit 006abfc into master Nov 2, 2024
21 checks passed
@tagliala tagliala deleted the chore/use-safe-navigation-operator branch November 2, 2024 22:00
tagliala added a commit that referenced this pull request Nov 2, 2024
Replace a logic `&&` with safe navigation operator now that Ruby < 2.3
support is not required anymore

Benchmark (Ruby 3.3.5 x64 / M1 Pro):

```
Comparison (not `nil`):
                  &.: 18787752.0 i/s
                  &&: 17963968.8 i/s - 1.05x  (± 0.00) slower

Comparison (`nil`):
                  &&: 21343215.5 i/s
                  &.: 20910008.5 i/s - 1.02x  (± 0.00) slower
```

Ref: #8530
tagliala added a commit that referenced this pull request Nov 7, 2024
Replace a logic `&&` with safe navigation operator now that Ruby < 2.3
support is not required anymore

Benchmark (Ruby 3.3.5 x64 / M1 Pro):

```
Comparison (not `nil`):
                  &.: 18787752.0 i/s
                  &&: 17963968.8 i/s - 1.05x  (± 0.00) slower

Comparison (`nil`):
                  &&: 21343215.5 i/s
                  &.: 20910008.5 i/s - 1.02x  (± 0.00) slower
```

Ref: #8530
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants