mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add class to deprecate instance variables
Add ActiveSupport::Deprecation::DeprecatedInstanceVariable class to deprecate instance variables of primitive types such as stings.
This commit is contained in:
parent
2c39836dc3
commit
a53331a161
2 changed files with 24 additions and 0 deletions
|
@ -175,6 +175,20 @@ module ActiveSupport
|
|||
ActiveSupport::Deprecation.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack)
|
||||
end
|
||||
end
|
||||
|
||||
class DeprecatedInstanceVariable < Delegator #:nodoc:
|
||||
def initialize(value, method)
|
||||
super(value)
|
||||
@method = method
|
||||
@value = value
|
||||
end
|
||||
|
||||
def __getobj__
|
||||
ActiveSupport::Deprecation.warn("Instance variable @#{@method} is deprecated! Call instance method #{@method} instead.")
|
||||
@value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -149,3 +149,13 @@ class DeprecationTest < Test::Unit::TestCase
|
|||
assert_nil @last_message
|
||||
end
|
||||
end
|
||||
|
||||
class DeprecatedIvarTest < Test::Unit::TestCase
|
||||
|
||||
def test_deprecated_ivar
|
||||
@action = ActiveSupport::Deprecation::DeprecatedInstanceVariable.new("fubar", :foobar)
|
||||
|
||||
assert_deprecated(/Instance variable @foobar is deprecated! Call instance method foobar instead/) { assert_equal "fubar", @action }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue