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
Allow ActiveSupport::Deprecation features to be used by rails applications and library authors #6348
Allow ActiveSupport::Deprecation features to be used by rails applications and library authors #6348
Conversation
|
@jeremy done :) |
|
||
# Default warning behaviors per Rails.env. | ||
DEFAULT_BEHAVIORS = { |
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.
Should probably leave these as a constant since it acts as public API now. People add behaviors to this hash directly.
@LTe Very nice! Looking good. |
# Example | ||
# OLD_CONST = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OLD_CONST', 'NEW_CONST') | ||
# Example with custom deprecator | ||
# OLD_CONST = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OLD_CONST', 'NEW_CONST'. deprecator_instance) |
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.
Typo: .
instead of ,
after NEW_CONST
.
@carlosantoniodasilva @jeremy thanks for feedback! |
What do you think about it: module ActiveSupport
class Deprecation
def initialize(horizon = '3.2', gem_name = 'rails')
self.deprecation_horizon = horizon
self.gem_name = gem_name
end
end
end For custom gems authors should create new instances of These: deprecator = ActiveSupport::Deprecation.new
deprecator.deprecation_horizon = "2.0.0" ActiveSupport::Deprecation.new.tap{|d| d.deprecation_horizon = "2.0.0" } seem to be unnecessary verbose to me. ActiveSupport::Deprecation.new("2.0.0", "formtastic") looks much better imho. |
Science Fiction: module ActiveSupport
class Deprecation
def initialize(horizon = default_horizon, gem_name = 'rails')
self.deprecation_horizon = horizon
self.gem_name = gem_name
end
def default_horizon
"#{ActiveSupport::VERSION::MAJOR}.#{ActiveSupport::VERSION::MINOR + 1}"
end
end
end because sometimes it should be |
Now you can create About science fiction I think better solution is pass directly version to initialize method. |
"About science fiction I think better solution is pass directly version to initialize method." - probably. Except for the fact that the core team needs to change this one line every time there is new rails version. I wanted to spare them this trouble in this science fiction solution :) |
According to http://semver.org/ this always should be |
@jeremy what do you think? We can merge current implementation? |
# [+log+] Log all deprecation warnings to +Rails.logger+. | ||
# [+notify+] Use <tt>ActiveSupport::Notifications</tt> to notify +deprecation.rails+. | ||
# [+notify] Use +ActiveSupport::Notifications+ to notify +deprecation.rails+. |
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.
[+notify+]
formatting changed?
@jeremy updated and rebased |
# Default warning behaviors per Rails.env. | ||
DEFAULT_BEHAVIORS = { | ||
:stderr => Proc.new { |message, callstack| | ||
$stderr.puts(message) |
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.
Extra indentation here
@LTe some comments on the documentation :) It covers how to give a custom deprecator object, but doesn't show how you can use When I read through the duck type for a deprecator, having to implement two methods seems wrong, too. We call |
@jeremy - I think that's because |
@paneq definitely -- and a higher-level method like |
Updated |
@jeremy what do you think about merge? |
@LTe it needs rebased at least, it can't be merged cleanly anymore. |
@steveklabnik rebased ;-) |
Thanks. Let's see what @jeremy says. |
What do you think @jeremy ? |
👍 |
# Kernel.warn message | ||
# end | ||
# | ||
# end |
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.
Please remove whitespaces between the method and class declaration, there's no need for them ✂️
@LTe hey, could you please add a changelog entry for this, and check the minor comments I made, so that we can get this in master? Thanks! |
@carlosantoniodasilva updated, rebased. |
@LTe, great thanks. I'll have to ask you one more thing though, to review your commit message and improve the changelog a bit with an example of how to use this new feature. This will help others to understand the reasoning and how to use the feature at the same time when reading the commits or the changelog. Here's an explanation about how to go with the commit message, and here's another about changelogs. I'll merge it afterwards. Thanks! |
…xtend/include it also. test local deprecation deprecator object Test ActiveSupport::Deprecation when included
ActiveSupport::Deprecation is now a class rather than a module. You can get instance of ActiveSupport::Deprecation calling #instance method. ActiveSupport::Deprecation.instance But when you need to get new object od ActiveSupport::Deprecation you need to just call #new. @instance = ActiveSupport::Deprecation.new Since you can create a new object, you can change the version and the name of the library where the deprecator concerned. ActiveSupport::Deprecation.new('2.0', 'MyGem') If you need use another deprecator instance you can select it in the options of deprecate method. deprecate :method, :deprecator => deprecator_instance Documentation has been updated.
@carlosantoniodasilva updated |
@LTe great, thank you! |
Allow ActiveSupport::Deprecation features to be used by rails applications and library authors
Updated version of #2310