rb: Add docstrings to generated ruby code [THRIFT-147]
Author: Bryan Duxbury
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@709309 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 570b4a7..c6122ce 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -136,6 +136,9 @@
t_list* tlist,
std::string iter);
+ void generate_rdoc (std::ofstream& out,
+ t_doc* tdoc);
+
/**
* Helper rendering functions
*/
@@ -443,11 +446,12 @@
* 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 @@
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 @@
}
+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", "");