提交 a53331a1 编写于 作者: P Pratik Naik

Add class to deprecate instance variables

Add ActiveSupport::Deprecation::DeprecatedInstanceVariable class to
deprecate instance variables of primitive types such as stings.
上级 2c39836d
......@@ -175,6 +175,20 @@ def warn(callstack, called, args)
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 @@ def message
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册