From cfca336fad004b6a41b13d02b3f1da86d2e7cae0 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Fri, 31 Oct 2008 00:32:25 +0000 Subject: [PATCH] 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 --- compiler/cpp/src/generate/t_rb_generator.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc index 570b4a7f..c6122ce4 100644 --- a/compiler/cpp/src/generate/t_rb_generator.cc +++ b/compiler/cpp/src/generate/t_rb_generator.cc @@ -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", ""); -- 2.17.1