Lots of Ruby code generation improvements

Summary: Submitted by Kevin Clark, Ruby guru from Powerset

Reviewed By: mcslee

Test Plan: He updated the tests in trunk/test/rb/

Notes: The code is now officially "ruby-ish" and idiomatic


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665151 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift
index d4b0a4d..92a3d21 100644
--- a/test/ThriftTest.thrift
+++ b/test/ThriftTest.thrift
@@ -1,5 +1,6 @@
 java_package thrift.test
 cpp_namespace thrift.test
+ruby_namespace Thrift.Test
 
 enum Numberz
 {
diff --git a/test/rb/TestClient.rb b/test/rb/TestClient.rb
index fedb818..1adb5c7 100755
--- a/test/rb/TestClient.rb
+++ b/test/rb/TestClient.rb
@@ -9,7 +9,7 @@
 
 s = TSocket.new('localhost', 9090)
 p = TBinaryProtocol.new(s)
-c = ThriftTest::Client.new(p)
+c = Thrift::Test::ThriftTest::Client.new(p)
 
 s.open()
 
@@ -25,10 +25,12 @@
 puts c.testMap({1 => 1, 2 => 2, 3 => 3})
 puts c.testList([1,2,3,4,5])
 puts c.testSet({1 => true, 2 => true, 3 => true})
-
-struct = Xtruct.new({'string_thing' => 'hi!', 'i32_thing' => 4 })
+struct = Thrift::Test::Xtruct.new({'string_thing' => 'hi!', 'i32_thing' => 4 })
 puts c.testStruct(struct)
-puts c.testNest(Xtruct2.new({'struct_thing' => struct, 'i32_thing' => 10}))
+puts c.testNest(Thrift::Test::Xtruct2.new({'struct_thing' => struct, 'i32_thing' => 10}))
+insane = Thrift::Test::Insanity.new({'userMap' => { Thrift::Test::Numberz::ONE => 44 }, 'xtructs' => [struct, Thrift::Test::Xtruct.new({'string_thing' => 'hi again', 'i32_thing' => 12})]})
+puts c.testInsanity(insane)
+puts c.testMapMap(4).inspect
 
 s.close()
 
diff --git a/test/rb/TestServer.rb b/test/rb/TestServer.rb
index c0d7b59..892037e 100755
--- a/test/rb/TestServer.rb
+++ b/test/rb/TestServer.rb
@@ -9,8 +9,6 @@
 require 'ThriftTest'
 
 class TestHandler
-  include ThriftTest::Iface
-  
   def testVoid()
     print "testVoid()\n"
   end
@@ -42,6 +40,7 @@
 
   def testStruct(thing)
     print "testStruct(#{thing})\n"
+    print "  with attrs: #{thing.string_thing}, #{thing.byte_thing}, #{thing.i32_thing}"
     return thing
   end
 
@@ -69,11 +68,33 @@
     end
     return thing
   end
+  
+  def testNest(thing)
+    print "testNest(#{thing})\n"
+    puts "  i32_thing: #{thing.i32_thing}"
+    puts "  with struct: "
+    %w{ string_thing byte_thing i32_thing }.each do |t|
+      puts "    #{t}: #{thing.struct_thing.send(t)}"
+    end
+    return thing
+  end
+  
+  def testInsanity(thing)
+    puts "insanity:"
+    puts "  #{thing.inspect}"
+    num, uid = thing.userMap.find { true }
+    return {uid => {num => thing}}
+  end
+
+  def testMapMap(thing)
+    puts "got: #{thing}"
+    return {thing => {thing => thing}}
+  end
 
 end
 
 handler = TestHandler.new()
-processor = ThriftTest::Processor.new(handler)
+processor = Thrift::Test::ThriftTest::Processor.new(handler)
 transport = TServerSocket.new(9090)
 server = TSimpleServer.new(processor, transport)
 server.serve()