-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add Rails.application.deprecators
#46049
Add Rails.application.deprecators
#46049
Conversation
|
||
# | ||
def [](name) | ||
# TODO? automatically instantiate a deprecator when it does not exist? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but I'd not do it now and only do it later if it makes sense for the framework's own usage.
|
||
# | ||
def []=(name, deprecator) | ||
# TODO? save configuration from setters (e.g. `#silenced=`) and apply |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense.
01add7e
to
c4e99ae
Compare
c4e99ae
to
f3b53c7
Compare
f3b53c7
to
e9ba80e
Compare
This adds a `Rails.application.deprecators` method that returns a managed collection of deprecators. Individual deprecators can be added and retrieved from the collection: ```ruby Rails.application.deprecators[:my_gem] = ActiveSupport::Deprecation.new("2.0", "MyGem") Rails.application.deprecators[:other_gem] = ActiveSupport::Deprecation.new("3.0", "OtherGem") ``` And the collection's configuration methods affect all deprecators in the collection: ```ruby Rails.application.deprecators.debug = true Rails.application.deprecators[:my_gem].debug # => true Rails.application.deprecators[:other_gem].debug # => true ``` Additionally, all deprecators in the collection can be silenced for the duration of a given block: ```ruby Rails.application.deprecators.silence do Rails.application.deprecators[:my_gem].warn # => silenced (no warning) Rails.application.deprecators[:other_gem].warn # => silenced (no warning) end ```
e9ba80e
to
d240e8a
Compare
Hi @jonathanhefner. |
@p8 Close, but it would be Dalli registering Before this PR, if a library created its own deprecator instance, users of the library would have to seek out and configure that instance separately from the global MyGem.deprecator = ActiveSupport::Deprecation.new("2.0", "my_gem") and a user wanted to set ActiveSupport::Deprecation.behavior = :raise
MyGem.deprecator.behavior = :raise And so on for each library with its own deprecator instance. With this PR, each library can have an initializer like: module MyGem
class Railtie < ::Rails::Railtie
initializer :deprecator do |app|
app.deprecators[:my_gem] = MyGem.deprecator
end
end
end And then the user will only have to write: Rails.application.deprecators.behavior = :raise Alternatively, if the user wants to change the behavior for a single deprecator, they now have a standard location to do so: Rails.application.deprecators[:my_gem].behavior = :raise And all the above also applies to the |
Ok clear. Thanks @jonathanhefner ! |
Follow-up to rails#46049 and rails#47354. Since `Rails.deprecator` is now a new `ActiveSupport::Deprecation` instance instead of `ActiveSupport::Deprecation.instance`, it makes sense to register it as `Rails.application.deprecators[:railties]` instead of `Rails.application.deprecators[:rails]`.
Follow-up to rails#46049 and rails#47354. Since `Rails.deprecator` is now a new `ActiveSupport::Deprecation` instance instead of `ActiveSupport::Deprecation.instance`, it makes sense to register it as `Rails.application.deprecators[:railties]` instead of `Rails.application.deprecators[:rails]`.
Follow-up to rails#46049 and rails#47354. Since `Rails.deprecator` is now a new `ActiveSupport::Deprecation` instance instead of `ActiveSupport::Deprecation.instance`, it makes sense to register it as `Rails.application.deprecators[:railties]` instead of `Rails.application.deprecators[:rails]`.
Follow-up to rails#46049 and rails#47354. Since `Rails.deprecator` is now a new `ActiveSupport::Deprecation` instance instead of `ActiveSupport::Deprecation.instance`, it makes sense to register it as `Rails.application.deprecators[:railties]` instead of `Rails.application.deprecators[:rails]`.
This adds a
Rails.application.deprecators
method that returns a managed collection of deprecators.Individual deprecators can be added and retrieved from the collection:
And the collection's configuration methods affect all deprecators in the collection:
Additionally, all deprecators in the collection can be silenced for the duration of a given block: