rb: Add docstrings to generated ruby code [THRIFT-147]
authorKevin Clark <kclark@apache.org>
Fri, 31 Oct 2008 00:32:25 +0000 (00:32 +0000)
committerKevin Clark <kclark@apache.org>
Fri, 31 Oct 2008 00:32:25 +0000 (00:32 +0000)
Author: Bryan Duxbury

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@709309 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_rb_generator.cc

index 570b4a7..c6122ce 100644 (file)
@@ -136,6 +136,9 @@ class t_rb_generator : public t_oop_generator {
                                           t_list*     tlist,
                                           std::string iter);
 
+  void generate_rdoc                     (std::ofstream& out, 
+                                          t_doc* tdoc);
+
   /**
    * Helper rendering functions
    */
@@ -443,11 +446,12 @@ void t_rb_generator::generate_xception(t_struct* txception) {
  * Generates a ruby struct
  */
 void t_rb_generator::generate_rb_struct(std::ofstream& out, t_struct* tstruct, bool is_exception = false) {
+  generate_rdoc(out, tstruct);
   indent(out) << "class " << type_name(tstruct);
   if (is_exception) {
     out << " < StandardError";
   }
-  out  << endl;
+  out << endl;
 
   indent_up();
   indent(out) << "include Thrift::Struct" << endl;
@@ -524,6 +528,9 @@ void t_rb_generator::generate_field_defns(std::ofstream& out, t_struct* tstruct)
       out << "," << endl;
     }
 
+    // generate the field docstrings within the FIELDS constant. no real better place...
+    generate_rdoc(out, *f_iter);
+
     indent(out) <<
       upcase_string((*f_iter)->get_name()) << " => ";
 
@@ -1013,4 +1020,11 @@ string t_rb_generator::type_to_enum(t_type* type) {
 }
 
 
+void t_rb_generator::generate_rdoc(std::ofstream& out, t_doc* tdoc) {
+  if (tdoc->has_doc()) {
+    generate_docstring_comment(out,
+      "", "# ", tdoc->get_doc(), "");
+  }
+}
+
 THRIFT_REGISTER_GENERATOR(rb, "Ruby", "");