Author: kclark
Date: Tue Jun 17 18:01:40 2008
New Revision: 668928
URL: http://svn.apache.org/viewvc?rev=668928&view=rev
Log:
Use the correct name in deprecation warnings
Modified:
incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb
incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb
Modified: incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb?rev=668928&r1=668927&r2=668928&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb Tue Jun 17 18:01:40
2008
@@ -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
Modified: incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb?rev=668928&r1=668927&r2=668928&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/deprecation_spec.rb Tue Jun 17 18:01:40
2008
@@ -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