Use the correct name in deprecation warnings


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668928 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/lib/thrift/deprecation.rb b/lib/rb/lib/thrift/deprecation.rb
index f2b57ae..68ecb71 100644
--- a/lib/rb/lib/thrift/deprecation.rb
+++ b/lib/rb/lib/thrift/deprecation.rb
@@ -32,7 +32,7 @@
 end
 
 module Thrift::DeprecationProxy
-  def self.new_class(obj)
+  def self.new_class(obj, name)
     Class.new(obj) do
       klass = self
       @@self = klass
@@ -46,13 +46,14 @@
       (class << self;self;end).class_eval do
         @@self = klass
         @@obj = obj
+        @@name = name
         @@warned = false
         instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym|
           undef_method sym
         end
         def method_missing(sym, *args, &block)
           unless @@warned
-            STDERR.puts "Warning: class #{@@obj.inspect} is deprecated"
+            STDERR.puts "Warning: class #{@@name} is deprecated"
             STDERR.puts "  from #{caller.first}"
             @@warned = true
           end
@@ -65,17 +66,21 @@
       end
     end
   end
-  def self.new_module(obj)
+  def self.new_module(obj, name)
     Module.new do
       @@obj = obj
-      @warned = false
+      @@warned = false
+      @@name = name
       include obj
       instance_methods.sort.reject { |x| [:__id__,:__send__].include? x.to_sym }.each do |sym|
         undef_method sym
       end
       def method_missing(sym, *args, &block)
-        STDERR.puts "Warning: module #{@@obj.inspect} is deprecated"
-        STDERR.puts "  from #{caller.first}"
+        unless @@warned
+          STDERR.puts "Warning: module #{@@name} is deprecated"
+          STDERR.puts "  from #{caller.first}"
+          @@warned = true
+        end
         @@obj.instance_method(sym).bind(self).call(*args, &block)
       end
       (class << self;self;end).class_eval do
@@ -86,7 +91,7 @@
         end
         def method_missing(sym, *args, &block)
           unless @@warned
-            STDERR.puts "Warning: module #{@@obj.inspect} is deprecated"
+            STDERR.puts "Warning: module #{@@name} is deprecated"
             STDERR.puts "  from #{caller.first}"
             @@warned = true
           end
@@ -108,7 +113,8 @@
   def deprecate_class!(klasses)
     return unless Thrift::DEPRECATION
     klasses.each_pair do |old, new|
-      Object.const_set old, Thrift::DeprecationProxy.new_class(new)
+      raise "deprecate_class! expected Class, called with #{new}" unless new.is_a? Class
+      Object.const_set old, Thrift::DeprecationProxy.new_class(new, old)
     end
   end
 
@@ -116,7 +122,7 @@
   def deprecate_module!(modules)
     return unless Thrift::DEPRECATION
     modules.each_pair do |old, new|
-      Object.const_set old, Thrift::DeprecationProxy.new_module(new)
+      Object.const_set old, Thrift::DeprecationProxy.new_module(new, old)
     end
   end
 end
diff --git a/lib/rb/spec/deprecation_spec.rb b/lib/rb/spec/deprecation_spec.rb
index 0b994fd..9e27f7c 100644
--- a/lib/rb/spec/deprecation_spec.rb
+++ b/lib/rb/spec/deprecation_spec.rb
@@ -190,7 +190,7 @@
         end
       end
       deprecate_class! :DeprecationSpecOldClass => klass
-      stub_stderr(klass)
+      stub_stderr(:DeprecationSpecOldClass)
       ::DeprecationSpecOldClass.should eql(klass)
       ::DeprecationSpecOldClass.new.foo.should == "foo"
     end
@@ -207,7 +207,7 @@
         end
         deprecate_class! :DeprecationSpecOldClass => klass
       end
-      stub_stderr(klass)
+      stub_stderr(:DeprecationSpecOldClass)
       ::DeprecationSpecOldClass.should eql(klass)
       ::DeprecationSpecOldClass.new.foo.should == "foo"
     end
@@ -226,7 +226,7 @@
           "subclass #{super}"
         end
       end
-      stub_stderr(klass)
+      stub_stderr(:DeprecationSpecOldClass)
       subklass.superclass.should eql(klass)
       subklass.new.foo.should == "subclass foo"
     end
@@ -250,7 +250,7 @@
         end
       end
       deprecate_module! :DeprecationSpecOldModule => mod
-      stub_stderr(mod)
+      stub_stderr(:DeprecationSpecOldModule)
       ::DeprecationSpecOldModule.should eql(mod)
       ::DeprecationSpecOldModule.foo.should == "foo"
     end
@@ -267,7 +267,7 @@
         end
         deprecate_module! :DeprecationSpecOldModule => mod
       end
-      stub_stderr(mod)
+      stub_stderr(:DeprecationSpecOldModule)
       ::DeprecationSpecOldModule.should eql(mod)
       ::DeprecationSpecOldModule.foo.should == "foo"
     end
@@ -282,7 +282,7 @@
         end
       end
       deprecate_module! :DeprecationSpecOldModule => mod
-      stub_stderr(mod)
+      stub_stderr(:DeprecationSpecOldModule)
       ::DeprecationSpecOldModule.should eql(mod)
       ::DeprecationSpecOldModule.foo.should == "foo"
     end
@@ -301,7 +301,7 @@
           include ::DeprecationSpecOldModule
         end
       end
-      stub_stderr(mod)
+      stub_stderr(:DeprecationSpecOldModule)
       mod2.foo.should == "foo"
     end
   end
@@ -317,7 +317,7 @@
       klass = Class.new do
         include ::DeprecationSpecOldModule
       end
-      stub_stderr(mod)
+      stub_stderr(:DeprecationSpecOldModule)
       klass.new.foo.should == "foo"
     end
   end