diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-05 06:33:28 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-05 06:33:28 +0000 |
commit | 0e73a92c0441fb7faec3ac44dbaa8fbf8335df10 (patch) | |
tree | c328dfd3f4a566f0fe5332e130ae80b99c2f7ced /activesupport/lib/active_support | |
parent | 6c5059748903971ce105c419ec775a58ae97c54c (diff) | |
download | rails-0e73a92c0441fb7faec3ac44dbaa8fbf8335df10.tar.gz rails-0e73a92c0441fb7faec3ac44dbaa8fbf8335df10.tar.bz2 rails-0e73a92c0441fb7faec3ac44dbaa8fbf8335df10.zip |
DeprecatedInstanceVariableProxy stand-in for @request, @attributes, and friends.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4666 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/deprecation.rb | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb index 77c00f5a67..2e92cbfbf3 100644 --- a/activesupport/lib/active_support/deprecation.rb +++ b/activesupport/lib/active_support/deprecation.rb @@ -48,12 +48,11 @@ module ActiveSupport end module Assertions - def assert_deprecated(regexp = nil, &block) + def assert_deprecated(match = nil, &block) last = with_last_message_tracking_deprecation_behavior(&block) assert last, "Expected a deprecation warning within the block but received none" - if regexp - assert_match regexp, last, "Deprecation warning didn't match #{regexp}: #{last}" - end + match = Regexp.new(match) unless match.is_a?(Regexp) + assert_match match, last, "Deprecation warning didn't match #{match}: #{last}" end def assert_not_deprecated(&block) @@ -72,6 +71,26 @@ module ActiveSupport ActiveSupport::Deprecation.behavior = old_behavior end end + + # Stand-in for @request, @attributes, etc. + class DeprecatedInstanceVariableProxy + instance_methods.each { |m| undef_method m unless m =~ /^__/ } + + def initialize(instance, method, var = "@#{method}") + @instance, @method, @var = instance, method, var + deprecation_warning :initialize, caller + end + + private + def deprecation_warning(called, callstack) + ActiveSupport::Deprecation.warn("Using #{@var} directly is deprecated - call #{@method} instead.", callstack) + end + + def method_missing(called, *args, &block) + deprecation_warning called, caller + @instance.__send__(@method).__send__(called, *args, &block) + end + end end end |