Skip to content

Commit

Permalink
Show warnings about deprecations only once per method + caller pair
Browse files Browse the repository at this point in the history
  • Loading branch information
tadman committed Jun 2, 2011
1 parent 79ea51c commit 033bd69
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/rubygems/deprecate.rb
Expand Up @@ -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.

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 033bd69

Please sign in to comment.