lib/deprecation/behaviors.rb in deprecation-0.1.0 vs lib/deprecation/behaviors.rb in deprecation-0.2.0
- old
+ new
@@ -37,11 +37,11 @@
def deprecation_behavior=(deprecation_behavior)
@deprecation_behavior = Array(deprecation_behavior).map { |b| Deprecation.behaviors(self)[b] || b }
end
def self.deprecations
- @deprecations ||= []
+ @deprecations ||= {}
end
def self.behaviors klass
# Default warning behaviors per Rails.env.
{
@@ -58,9 +58,26 @@
ActiveSupport::Notifications.instrument("deprecation.#{klass.to_s}",
:message => message, :callstack => callstack)
},
:raise => Proc.new { |message, callstack| raise message },
:silence => Proc.new { |message, callstack| },
- :test => Proc.new { |message, callstack| self.deprecations << message }
+ :test => Proc.new do |message, callstack|
+ hash = message.hash + callstack[0..2].join("\n").hash
+ unless self.deprecations[hash]
+ self.deprecations[hash] = { message: message, callstack: callstack, count: 1 }
+ else
+ self.deprecations[hash][:count] += 1
+ end
+ end,
+ :stderr_report => Proc.new do |message, callstack|
+ hash = message.hash + callstack[0..2].join("\n").hash
+ unless self.deprecations[hash]
+ self.deprecations[hash] = { message: message, callstack: callstack, count: 1 }
+ $stderr.puts(message)
+ $stderr.puts callstack.join("\n ") if klass.respond_to? :debug and klass.debug
+ else
+ self.deprecations[hash][:count] += 1
+ end
+ end
}
end
end