lib/deprecation/reporting.rb in deprecation-0.0.5 vs lib/deprecation/reporting.rb in deprecation-0.1.0
- old
+ new
@@ -3,22 +3,39 @@
attr_accessor :show_full_callstack
# Outputs a deprecation warning to the output configured by <tt>ActiveSupport::Deprecation.behavior</tt>
#
# Deprecation.warn("something broke!")
# # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
- def warn(context, message = nil, callstack = caller)
- return if context.silenced
+ def warn(context, message = nil, callstack = nil)
+ return if context.respond_to? :silenced? and context.silenced?
+
+ if callstack.nil?
+ callstack = caller
+ callstack.shift
+ end
+
deprecation_message(callstack, message).tap do |m|
- context.deprecation_behavior.each { |b| b.call(m, callstack) }
+ deprecation_behavior(context).each { |b| b.call(m, callstack) }
end
end
+ def deprecation_behavior context
+ if context.respond_to? :deprecation_behavior
+ context.deprecation_behavior
+ else
+ [Deprecation.behaviors(self)[Deprecation.default_deprecation_behavior]]
+ end
+ end
+
# Silence deprecation warnings within the block.
def silence context
- old_silenced, context.silenced = context.silenced, true
+ if context.respond_to? :silenced=
+ old_silenced, context.silenced = context.silenced, true
+ end
+
yield
ensure
- context.silenced = old_silenced
+ context.silenced = old_silenced if context.respond_to? :silenced=
end
def collect(context)
old_behavior = context.deprecation_behavior
deprecations = []