THRIFT-246. rb: Generate #struct_fields rather than reflect.

Author: Bryan Duxbury


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@731806 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index b2fc5bc..e3c3031 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -540,7 +540,10 @@
   }
   indent_down();
   out << endl;
-  indent(out) << "}" << endl;
+  indent(out) << "}" << endl << endl;
+  
+  indent(out) << "def struct_fields; FIELDS; end" << endl << endl;
+  
 }
 
 void t_rb_generator::generate_field_data(std::ofstream& out, t_type* field_type,
diff --git a/lib/rb/benchmark/gen-rb/BenchmarkService.rb b/lib/rb/benchmark/gen-rb/BenchmarkService.rb
index 2c3ae4f..832098b 100644
--- a/lib/rb/benchmark/gen-rb/BenchmarkService.rb
+++ b/lib/rb/benchmark/gen-rb/BenchmarkService.rb
@@ -52,6 +52,9 @@
           FIELDS = {
             N => {:type => Thrift::Types::BYTE, :name => 'n'}
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -65,6 +68,9 @@
           FIELDS = {
             SUCCESS => {:type => Thrift::Types::I32, :name => 'success'}
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb
index 25eb981..d790bd4 100644
--- a/lib/rb/lib/thrift/struct.rb
+++ b/lib/rb/lib/thrift/struct.rb
@@ -60,6 +60,8 @@
       names_to_ids[name]
     end
 
+    # Obsoleted by THRIFT-246, which generates this method inline
+    # TODO: Should be removed at some point. -- Kevin Clark
     def struct_fields
       self.class.const_get(:FIELDS)
     end
diff --git a/lib/rb/spec/gen-rb/NonblockingService.rb b/lib/rb/spec/gen-rb/NonblockingService.rb
index 8044d8e..3b49fce 100644
--- a/lib/rb/spec/gen-rb/NonblockingService.rb
+++ b/lib/rb/spec/gen-rb/NonblockingService.rb
@@ -121,6 +121,9 @@
           FIELDS = {
             ENGLISH => {:type => Thrift::Types::BOOL, :name => 'english'}
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -134,6 +137,9 @@
           FIELDS = {
             SUCCESS => {:type => Thrift::Types::STRUCT, :name => 'success', :class => SpecNamespace::Hello}
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -145,6 +151,9 @@
           FIELDS = {
 
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -158,6 +167,9 @@
           FIELDS = {
             SUCCESS => {:type => Thrift::Types::BOOL, :name => 'success'}
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -171,6 +183,9 @@
           FIELDS = {
             N => {:type => Thrift::Types::I32, :name => 'n'}
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -182,6 +197,9 @@
           FIELDS = {
 
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -193,6 +211,9 @@
           FIELDS = {
 
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -204,6 +225,9 @@
           FIELDS = {
 
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -217,6 +241,9 @@
           FIELDS = {
             SECONDS => {:type => Thrift::Types::DOUBLE, :name => 'seconds'}
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
@@ -228,6 +255,9 @@
           FIELDS = {
 
           }
+
+          def struct_fields; FIELDS; end
+
           def validate
           end
 
diff --git a/lib/rb/spec/gen-rb/ThriftSpec_types.rb b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
index a28c921..ea73af1 100644
--- a/lib/rb/spec/gen-rb/ThriftSpec_types.rb
+++ b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
@@ -15,6 +15,9 @@
       FIELDS = {
         GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', :default => %q"hello world"}
       }
+
+      def struct_fields; FIELDS; end
+
       def validate
       end
 
@@ -50,6 +53,9 @@
         ]), :element => {:type => Thrift::Types::I16}},
         OPT_STRING => {:type => Thrift::Types::STRING, :name => 'opt_string', :optional => true}
       }
+
+      def struct_fields; FIELDS; end
+
       def validate
       end
 
@@ -63,6 +69,9 @@
       FIELDS = {
         YESNO => {:type => Thrift::Types::BOOL, :name => 'yesno', :default => true}
       }
+
+      def struct_fields; FIELDS; end
+
       def validate
       end
 
@@ -96,6 +105,9 @@
         SETS => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
         HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}}
       }
+
+      def struct_fields; FIELDS; end
+
       def validate
       end
 
@@ -111,6 +123,9 @@
         MESSAGE => {:type => Thrift::Types::STRING, :name => 'message'},
         CODE => {:type => Thrift::Types::I32, :name => 'code', :default => 1}
       }
+
+      def struct_fields; FIELDS; end
+
       def validate
       end