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

Support using a method name to define the ActiveSupport::CurrentAttributes.resets callback #45698

Merged
merged 1 commit into from Nov 17, 2022

Conversation

ghiculescu
Copy link
Member

@ghiculescu ghiculescu commented Jul 29, 2022

Previously you could only use a block, which was inconsistent with other callback APIs in Rails. Now, you can use a block or a method name. The block API is still recommended in the docs. So now these do the same thing:

class CurrentWithBlock < ActiveSupport::CurrentAttributes
  resets { Time.zone = nil }
end

class CurrentWithMethod < ActiveSupport::CurrentAttributes
  resets :clear_time_zone

  def clear_time_zone
    Time.zone = nil
  end
end

This also works for before_reset.

class Current < ActiveSupport::CurrentAttributes
  before_reset :clear_time_zone
end

activesupport/CHANGELOG.md Outdated Show resolved Hide resolved
…ibutes.resets` callback

Previously you could only use a block, which was inconsistent with other callback APIs in Rails. Now, you can use a block or a method name. The block API is still recommended in the docs.

```ruby
class Current < ActiveSupport::CurrentAttributes
  resets { Time.zone = nil }
  resets :clear_time_zone
end
```

This also works for `before_reset`.

```ruby
class Current < ActiveSupport::CurrentAttributes
  before_reset { Time.zone = nil }
  before_reset :clear_time_zone
end
```
@p8 p8 added the ready PRs ready to merge label Oct 6, 2022
@rafaelfranca rafaelfranca merged commit 994bce4 into rails:main Nov 17, 2022
@ghiculescu ghiculescu deleted the as-current-resets branch November 18, 2022 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
activesupport ready PRs ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants