const std::string& option_string)
: t_oop_generator(program)
{
- (void) parsed_options;
(void) option_string;
out_dir_base_ = "gen-rb";
+
+ require_rubygems_ = (parsed_options.find("rubygems") != parsed_options.end());
}
/**
*/
std::string rb_autogen_comment();
+ std::string render_require_thrift();
std::string render_includes();
std::string declare_field(t_field* tfield);
std::string type_name(t_type* ttype);
std::ofstream f_consts_;
std::ofstream f_service_;
+ /** If true, add a "require 'rubygems'" line to the top of each gen-rb file. */
+ bool require_rubygems_;
};
// Print header
f_types_ <<
- rb_autogen_comment() << endl <<
+ rb_autogen_comment() << endl << render_require_thrift() <<
render_includes() << endl;
begin_namespace(f_types_, ruby_modules(program_));
f_consts_ <<
- rb_autogen_comment() << endl <<
+ rb_autogen_comment() << endl << render_require_thrift() <<
"require '" << underscore(program_name_) << "_types'" << endl <<
endl;
begin_namespace(f_consts_, ruby_modules(program_));
}
+/**
+ * Renders the require of thrift itself, and possibly of the rubygems dependency.
+ */
+string t_rb_generator::render_require_thrift() {
+ if (require_rubygems_) {
+ return "require 'rubygems'\nrequire 'thrift'\n";
+ } else {
+ return "require 'thrift'\n";
+ }
+}
+
/**
* Renders all the imports necessary for including another Thrift program
*/
f_service_.open(f_service_name.c_str());
f_service_ <<
- rb_autogen_comment() << endl <<
- "require 'thrift'" << endl;
+ rb_autogen_comment() << endl << render_require_thrift();
if (tservice->get_extends() != NULL) {
f_service_ <<
indent(out) << "end" << endl << endl;
}
-THRIFT_REGISTER_GENERATOR(rb, "Ruby", "")
-
+THRIFT_REGISTER_GENERATOR(rb, "Ruby",
+" rubygems: Add a \"require 'rubygems'\" line to the top of each generated file.\n")