end
module Thrift::DeprecationProxy
- def self.new_class(obj)
+ def self.new_class(obj, name)
Class.new(obj) do
klass = self
@@self = klass
(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
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
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
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
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
end
end
deprecate_class! :DeprecationSpecOldClass => klass
- stub_stderr(klass)
+ stub_stderr(:DeprecationSpecOldClass)
::DeprecationSpecOldClass.should eql(klass)
::DeprecationSpecOldClass.new.foo.should == "foo"
end
end
deprecate_class! :DeprecationSpecOldClass => klass
end
- stub_stderr(klass)
+ stub_stderr(:DeprecationSpecOldClass)
::DeprecationSpecOldClass.should eql(klass)
::DeprecationSpecOldClass.new.foo.should == "foo"
end
"subclass #{super}"
end
end
- stub_stderr(klass)
+ stub_stderr(:DeprecationSpecOldClass)
subklass.superclass.should eql(klass)
subklass.new.foo.should == "subclass foo"
end
end
end
deprecate_module! :DeprecationSpecOldModule => mod
- stub_stderr(mod)
+ stub_stderr(:DeprecationSpecOldModule)
::DeprecationSpecOldModule.should eql(mod)
::DeprecationSpecOldModule.foo.should == "foo"
end
end
deprecate_module! :DeprecationSpecOldModule => mod
end
- stub_stderr(mod)
+ stub_stderr(:DeprecationSpecOldModule)
::DeprecationSpecOldModule.should eql(mod)
::DeprecationSpecOldModule.foo.should == "foo"
end
end
end
deprecate_module! :DeprecationSpecOldModule => mod
- stub_stderr(mod)
+ stub_stderr(:DeprecationSpecOldModule)
::DeprecationSpecOldModule.should eql(mod)
::DeprecationSpecOldModule.foo.should == "foo"
end
include ::DeprecationSpecOldModule
end
end
- stub_stderr(mod)
+ stub_stderr(:DeprecationSpecOldModule)
mod2.foo.should == "foo"
end
end
klass = Class.new do
include ::DeprecationSpecOldModule
end
- stub_stderr(mod)
+ stub_stderr(:DeprecationSpecOldModule)
klass.new.foo.should == "foo"
end
end