You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by kc...@apache.org on 2008/06/18 02:52:27 UTC

svn commit: r668899 - in /incubator/thrift/trunk: lib/rb/lib/thrift/deprecation.rb lib/rb/lib/thrift/transport/ttransport.rb test/rb/core/transport/test_ttransport.rb

Author: kclark
Date: Tue Jun 17 17:52:26 2008
New Revision: 668899

URL: http://svn.apache.org/viewvc?rev=668899&view=rev
Log:
rb: Add deprecate! method Rename TTransport#readAll/isOpen, and deprecate

Added:
    incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb
Modified:
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/ttransport.rb
    incubator/thrift/trunk/test/rb/core/transport/test_ttransport.rb

Added: 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=668899&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/deprecation.rb Tue Jun 17 17:52:26 2008
@@ -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

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/transport/ttransport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/ttransport.rb?rev=668899&r1=668898&r2=668899&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/ttransport.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/ttransport.rb Tue Jun 17 17:52:26 2008
@@ -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

Modified: incubator/thrift/trunk/test/rb/core/transport/test_ttransport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/test/rb/core/transport/test_ttransport.rb?rev=668899&r1=668898&r2=668899&view=diff
==============================================================================
--- incubator/thrift/trunk/test/rb/core/transport/test_ttransport.rb (original)
+++ incubator/thrift/trunk/test/rb/core/transport/test_ttransport.rb Tue Jun 17 17:52:26 2008
@@ -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