rails icon indicating copy to clipboard operation
rails copied to clipboard

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

Open ghiculescu opened this issue 1 year ago • 0 comments

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 :reset_time_zone

  def reset_time_zone
    Time.zone = nil
  end
end

This also works for before_reset.

class Current < ActiveSupport::CurrentAttributes
  before_reset :reset_time_zone
end

ghiculescu avatar Jul 29 '22 16:07 ghiculescu