public
Description: PLEASE CHECK http://github.com/lifo/docrails/wikis
Homepage: http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
Clone URL: git://github.com/lifo/docrails.git
Add class to deprecate instance variables

Add ActiveSupport::Deprecation::DeprecatedInstanceVariable class to
deprecate instance variables of primitive types such as stings.
lifo (author)
Tue May 06 03:52:44 -0700 2008
commit  a53331a161f72b25f6e9c860db43acaf23250f68
tree    782fda5754ab5e2489f0bb6f0650774c190be125
parent  2c39836dc3c06813fce031d1bb390149b53ebd1c
...
175
176
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
179
180
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
0
@@ -175,6 +175,20 @@ module ActiveSupport
0
           ActiveSupport::Deprecation.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack)
0
         end
0
     end
0
+
0
+ class DeprecatedInstanceVariable < Delegator #:nodoc:
0
+ def initialize(value, method)
0
+ super(value)
0
+ @method = method
0
+ @value = value
0
+ end
0
+
0
+ def __getobj__
0
+ ActiveSupport::Deprecation.warn("Instance variable @#{@method} is deprecated! Call instance method #{@method} instead.")
0
+ @value
0
+ end
0
+ end
0
+
0
   end
0
 end
0
 
...
149
150
151
 
 
 
 
 
 
 
 
 
 
...
149
150
151
152
153
154
155
156
157
158
159
160
161
0
@@ -149,3 +149,13 @@ class DeprecationTest < Test::Unit::TestCase
0
     assert_nil @last_message
0
   end
0
 end
0
+
0
+class DeprecatedIvarTest < Test::Unit::TestCase
0
+
0
+ def test_deprecated_ivar
0
+ @action = ActiveSupport::Deprecation::DeprecatedInstanceVariable.new("fubar", :foobar)
0
+
0
+ assert_deprecated(/Instance variable @foobar is deprecated! Call instance method foobar instead/) { assert_equal "fubar", @action }
0
+ end
0
+
0
+end

Comments

    No one has commented yet.