rb: Add deprecate! method Rename TTransport#readAll/isOpen, and deprecate


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668899 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/lib/thrift/deprecation.rb b/lib/rb/lib/thrift/deprecation.rb
new file mode 100644
index 0000000..242a859
--- /dev/null
+++ b/lib/rb/lib/thrift/deprecation.rb
@@ -0,0 +1,19 @@
+class Module
+   def deprecate!(*method_names)
+     method_names.each do |method_name|
+       module_eval <<-END
+         alias_method :deprecated_#{method_name}, :#{method_name}
+         def #{method_name}(*args, &block)
+           $stderr.puts "Warning: calling deprecated method: #{self}.#{method_name}"
+           return deprecated_#{method_name}(*args, &block)
+         end
+       END
+      end
+   end
+end
+
+require 'thrift/transport/ttransport'
+
+class TTransport
+  deprecate! :isOpen, :readAll
+end
\ No newline at end of file
diff --git a/lib/rb/lib/thrift/transport/ttransport.rb b/lib/rb/lib/thrift/transport/ttransport.rb
index c53e405..a5f6a81 100644
--- a/lib/rb/lib/thrift/transport/ttransport.rb
+++ b/lib/rb/lib/thrift/transport/ttransport.rb
@@ -31,7 +31,7 @@
 # TTransport is basically an abstract class, but isn't raising NotImplementedError
 # TODO: Think about if this is the right thing - Kevin Clark - 3/27/08
 class TTransport
-  def isOpen; end
+  def is_open?; end
 
   def open; end
 
@@ -39,21 +39,34 @@
 
   def read(sz); end
 
-  def readAll(sz)
+  def read_all(size)
     buff = ''
     have = 0
-    while (have < sz)
-      chunk = read(sz - have)
+    
+    while (have < size)
+      chunk = read(size - have)
       have += chunk.length
       buff << chunk
     end
-    return buff
+    
+    buff
   end
-
+  
   def write(buf); end
 
   def flush; end
-
+  
+  ################
+  ## Deprecated
+  ################
+  
+  def isOpen
+    is_open?
+  end
+  
+  def readAll(sz)
+    read_all sz
+  end
 end
 
 class TServerTransport
diff --git a/test/rb/core/transport/test_ttransport.rb b/test/rb/core/transport/test_ttransport.rb
index 5811dec..bb876dc 100644
--- a/test/rb/core/transport/test_ttransport.rb
+++ b/test/rb/core/transport/test_ttransport.rb
@@ -18,8 +18,8 @@
     @trans = TTransport.new
   end
   
-  def test_isOpen
-    assert_nil @trans.isOpen
+  def test_is_open?
+    assert_nil @trans.is_open?
   end
   
   def test_open
@@ -39,7 +39,7 @@
   # It _looks_ like read isn't guarenteed to return the length
   # you ask for and readAll is. This means our test needs to check
   # for blocking. -- Kevin Clark 3/27/08
-  def test_readAll
+  def test_read_all
     # Implements read
     t = DummyTransport.new("hello")
     assert_equal "hello", t.readAll(5)
@@ -52,4 +52,20 @@
   def test_flush
     assert_nil @trans.flush
   end
+end
+
+class TestTTransportDeprecation < Test::Unit::TestCase
+  def setup
+    @trans = TTransport.new
+  end
+  
+  def test_isOpen
+    assert_nil @trans.isOpen
+  end
+    
+  def test_readAll
+    # Implements read
+    t = DummyTransport.new("hello")
+    assert_equal "hello", t.readAll(5)
+  end
 end
\ No newline at end of file