Skip to content
Browse files

Show warnings about deprecations only once per method + caller pair

  • Loading branch information...
1 parent 79ea51c commit 033bd6915c9fe29fad2b7055eb42b46377e596bf @tadman committed
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/rubygems/deprecate.rb
View
13 lib/rubygems/deprecate.rb
@@ -31,6 +31,15 @@ def self.skip= v # :nodoc:
@skip = v
end
+ def self.did_warn_about(name, for_caller)
+ @did_warn_about ||= Hash.new { |h,k| h[k] = 0 }
+
+ warning_count =
+ @did_warn_about[[ name, for_caller ]] += 1
+
+ warning_count > 1
+ end
+
##
# Temporarily turn off warnings. Intended for tests only.
@@ -59,7 +68,9 @@ def deprecate name, repl, year, month
". It will be removed on or after %4d-%02d-01." % [year, month],
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
]
- warn "#{msg.join}." unless Gem::Deprecate.skip
+ unless (Deprecate.skip or Deprecate.did_warn_about(name, caller[0]))
+ warn "#{msg.join}."
+ end
send old, *args, &block
end
}

0 comments on commit 033bd69

Please sign in to comment.
Something went wrong with that request. Please try again.