*/
void generate_rb_struct(std::ofstream& out, t_struct* tstruct, bool is_exception);
- void generate_rb_struct_reader(std::ofstream& out, t_struct* tstruct);
- void generate_rb_struct_writer(std::ofstream& out, t_struct* tstruct);
+ void generate_rb_struct_required_validator(std::ofstream& out, t_struct* tstruct);
void generate_rb_function_helpers(t_function* tfunction);
void generate_rb_simple_constructor(std::ofstream& out, t_struct* tstruct);
void generate_rb_simple_exception_constructor(std::ofstream& out, t_struct* tstruct);
generate_field_constants(out, tstruct);
generate_accessors(out, tstruct);
generate_field_defns(out, tstruct);
-
+ generate_rb_struct_required_validator(out, tstruct);
+
indent_down();
indent(out) << "end" << endl << endl;
}
}
}
+void t_rb_generator::generate_rb_struct_required_validator(std::ofstream& out,
+ t_struct* tstruct) {
+ indent(out) << "def validate" << endl;
+ indent_up();
+
+ const vector<t_field*>& fields = tstruct->get_members();
+ vector<t_field*>::const_iterator f_iter;
+
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ t_field* field = (*f_iter);
+ if (field->get_req() == t_field::T_REQUIRED) {
+ indent(out) << "raise Thrift::ProtocolException.new(Thrift::ProtocolException::UNKNOWN, 'Required field " << field->get_name() << " is unset!')";
+ if (field->get_type()->is_bool()) {
+ out << " if @" << field->get_name() << ".nil?";
+ } else {
+ out << " unless @" << field->get_name();
+ }
+ out << endl;
+ }
+ }
+
+ indent_down();
+ indent(out) << "end" << endl << endl;
+
+}
+
THRIFT_REGISTER_GENERATOR(rb, "Ruby", "");
end
def read(iprot)
+ validate
# TODO(kevinclark): Make sure transport is C readable
if iprot.respond_to?(:decode_binary)
iprot.decode_binary(self, iprot.trans)
end
def write(oprot)
+ validate
if oprot.respond_to?(:encode_binary)
# TODO(kevinclark): Clean this so I don't have to access the transport.
oprot.trans.write oprot.encode_binary(self)
FIELDS = {
ENGLISH => {:type => Thrift::Types::BOOL, :name => 'english'}
}
+ def validate
+ end
+
end
class Greeting_result
FIELDS = {
SUCCESS => {:type => Thrift::Types::STRUCT, :name => 'success', :class => Hello}
}
+ def validate
+ end
+
end
class Block_args
FIELDS = {
}
+ def validate
+ end
+
end
class Block_result
FIELDS = {
SUCCESS => {:type => Thrift::Types::BOOL, :name => 'success'}
}
+ def validate
+ end
+
end
class Unblock_args
FIELDS = {
N => {:type => Thrift::Types::I32, :name => 'n'}
}
+ def validate
+ end
+
end
class Unblock_result
FIELDS = {
}
+ def validate
+ end
+
end
class Shutdown_args
FIELDS = {
}
+ def validate
+ end
+
end
class Shutdown_result
FIELDS = {
}
+ def validate
+ end
+
end
class Sleep_args
FIELDS = {
SECONDS => {:type => Thrift::Types::DOUBLE, :name => 'seconds'}
}
+ def validate
+ end
+
end
class Sleep_result
FIELDS = {
}
+ def validate
+ end
+
end
end
FIELDS = {
GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', :default => 'hello world'}
}
+ def validate
+ end
+
end
class Foo
]), :element => {:type => Thrift::Types::I16}},
OPT_STRING => {:type => Thrift::Types::STRING, :name => 'opt_string', :optional => true}
}
+ def validate
+ end
+
end
class BoolStruct
FIELDS = {
YESNO => {:type => Thrift::Types::BOOL, :name => 'yesno', :default => true}
}
+ def validate
+ end
+
end
class SimpleList