Changeset 5356
- Timestamp:
- 10/24/06 16:56:59 (2 years ago)
- Files:
-
- trunk/activesupport/lib/active_support/deprecation.rb (modified) (2 diffs)
- trunk/activesupport/test/deprecation_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/deprecation.rb
r5161 r5356 72 72 # Declare that a method has been deprecated. 73 73 def deprecate(*method_names) 74 options = method_names.last.is_a?(Hash) ? method_names.pop : {} 75 method_names = method_names + options.keys 74 76 method_names.each do |method_name| 75 77 alias_method_chain(method_name, :deprecation) do |target, punctuation| 76 78 class_eval(<<-EOS, __FILE__, __LINE__) 77 79 def #{target}_with_deprecation#{punctuation}(*args, &block) 78 ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:#{method_name} ), caller)80 ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:#{method_name}, #{options[method_name].inspect}), caller) 79 81 #{target}_without_deprecation#{punctuation}(*args, &block) 80 82 end … … 84 86 end 85 87 86 def deprecated_method_warning(method_name) 87 "#{method_name} is deprecated and will be removed from Rails #{deprecation_horizon}" 88 def deprecated_method_warning(method_name, message=nil) 89 warning = "#{method_name} is deprecated and will be removed from Rails #{deprecation_horizon}" 90 case message 91 when Symbol then "#{warning} (use #{message} instead)" 92 when String then "#{warning} (#{message})" 93 else warning 94 end 88 95 end 89 96 trunk/activesupport/test/deprecation_test.rb
r5115 r5356 18 18 def multi(a,b,c) [a,b,c] end 19 19 deprecate :none, :one, :multi 20 21 def a; end 22 def b; end 23 def c; end 24 def d; end 25 def e; end 26 deprecate :a, :b, :c => :e, :d => "you now need to do something extra for this one" 20 27 end 21 28 … … 109 116 ActiveSupport::Deprecation.silenced = false 110 117 end 118 119 def test_deprecation_without_explanation 120 assert_deprecated { @dtc.a } 121 assert_deprecated { @dtc.b } 122 end 123 124 def test_deprecation_with_alternate_method 125 assert_deprecated(/use e instead/) { @dtc.c } 126 end 127 128 def test_deprecation_with_explicit_message 129 assert_deprecated(/you now need to do something extra for this one/) { @dtc.d } 130 end 111 131 end