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);
+ void generate_field_constants (std::ofstream& out, t_struct* tstruct);
void generate_accessors (std::ofstream& out, t_struct* tstruct);
void generate_field_defns (std::ofstream& out, t_struct* tstruct);
void generate_field_data (std::ofstream& out, t_type* field_type, const std::string& field_name, t_const_value* field_value, bool optional);
generate_rb_simple_exception_constructor(out, tstruct);
}
+ generate_field_constants(out, tstruct);
generate_accessors(out, tstruct);
generate_field_defns(out, tstruct);
}
}
+void t_rb_generator::generate_field_constants(std::ofstream& out, t_struct* tstruct) {
+ 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) {
+ std::string field_name = (*f_iter)->get_name();
+ std::string cap_field_name = upcase_string(field_name);
+
+ indent(out) << cap_field_name << " = " << (*f_iter)->get_key() << endl;
+ }
+ out << endl;
+}
+
void t_rb_generator::generate_accessors(std::ofstream& out, t_struct* tstruct) {
const vector<t_field*>& members = tstruct->get_members();
vector<t_field*>::const_iterator m_iter;
}
indent(out) <<
- (*f_iter)->get_key() << " => ";
+ upcase_string((*f_iter)->get_name()) << " => ";
generate_field_data(out, (*f_iter)->get_type(), (*f_iter)->get_name(), (*f_iter)->get_value(),
(*f_iter)->get_req() == t_field::T_OPTIONAL);
module SpecNamespace
class Hello
include Thrift::Struct
+ GREETING = 1
+
Thrift::Struct.field_accessor self, :greeting
FIELDS = {
- 1 => {:type => Thrift::Types::STRING, :name => 'greeting', :default => 'hello world'}
+ GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', :default => 'hello world'}
}
end
class Foo
include Thrift::Struct
+ SIMPLE = 1
+ WORDS = 2
+ HELLO = 3
+ INTS = 4
+ COMPLEX = 5
+ SHORTS = 6
+ OPT_STRING = 7
+
Thrift::Struct.field_accessor self, :simple, :words, :hello, :ints, :complex, :shorts, :opt_string
FIELDS = {
- 1 => {:type => Thrift::Types::I32, :name => 'simple', :default => 53},
- 2 => {:type => Thrift::Types::STRING, :name => 'words', :default => 'words'},
- 3 => {:type => Thrift::Types::STRUCT, :name => 'hello', :default => Hello.new({
+ SIMPLE => {:type => Thrift::Types::I32, :name => 'simple', :default => 53},
+ WORDS => {:type => Thrift::Types::STRING, :name => 'words', :default => 'words'},
+ HELLO => {:type => Thrift::Types::STRUCT, :name => 'hello', :default => Hello.new({
'greeting' => 'hello, world!',
}), :class => Hello},
- 4 => {:type => Thrift::Types::LIST, :name => 'ints', :default => [
+ INTS => {:type => Thrift::Types::LIST, :name => 'ints', :default => [
1,
2,
2,
3,
], :element => {:type => Thrift::Types::I32}},
- 5 => {:type => Thrift::Types::MAP, :name => 'complex', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::DOUBLE}}},
- 6 => {:type => Thrift::Types::SET, :name => 'shorts', :default => Set.new([ 5,
+ COMPLEX => {:type => Thrift::Types::MAP, :name => 'complex', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::DOUBLE}}},
+ SHORTS => {:type => Thrift::Types::SET, :name => 'shorts', :default => Set.new([ 5,
17,
239,
]), :element => {:type => Thrift::Types::I16}},
- 7 => {:type => Thrift::Types::STRING, :name => 'opt_string', :optional => true}
+ OPT_STRING => {:type => Thrift::Types::STRING, :name => 'opt_string', :optional => true}
}
end
class BoolStruct
include Thrift::Struct
+ YESNO = 1
+
Thrift::Struct.field_accessor self, :yesno
FIELDS = {
- 1 => {:type => Thrift::Types::BOOL, :name => 'yesno', :default => true}
+ YESNO => {:type => Thrift::Types::BOOL, :name => 'yesno', :default => true}
}
end
class SimpleList
include Thrift::Struct
+ BOOLS = 1
+ BYTES = 2
+ I16S = 3
+ I32S = 4
+ I64S = 5
+ DOUBLES = 6
+ STRINGS = 7
+ MAPS = 8
+ LISTS = 9
+ SETS = 10
+ HELLOS = 11
+
Thrift::Struct.field_accessor self, :bools, :bytes, :i16s, :i32s, :i64s, :doubles, :strings, :maps, :lists, :sets, :hellos
FIELDS = {
- 1 => {:type => Thrift::Types::LIST, :name => 'bools', :element => {:type => Thrift::Types::BOOL}},
- 2 => {:type => Thrift::Types::LIST, :name => 'bytes', :element => {:type => Thrift::Types::BYTE}},
- 3 => {:type => Thrift::Types::LIST, :name => 'i16s', :element => {:type => Thrift::Types::I16}},
- 4 => {:type => Thrift::Types::LIST, :name => 'i32s', :element => {:type => Thrift::Types::I32}},
- 5 => {:type => Thrift::Types::LIST, :name => 'i64s', :element => {:type => Thrift::Types::I64}},
- 6 => {:type => Thrift::Types::LIST, :name => 'doubles', :element => {:type => Thrift::Types::DOUBLE}},
- 7 => {:type => Thrift::Types::LIST, :name => 'strings', :element => {:type => Thrift::Types::STRING}},
- 8 => {:type => Thrift::Types::LIST, :name => 'maps', :element => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I16}, :value => {:type => Thrift::Types::I16}}},
- 9 => {:type => Thrift::Types::LIST, :name => 'lists', :element => {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I16}}},
- 10 => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
- 11 => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => Hello}}
+ BOOLS => {:type => Thrift::Types::LIST, :name => 'bools', :element => {:type => Thrift::Types::BOOL}},
+ BYTES => {:type => Thrift::Types::LIST, :name => 'bytes', :element => {:type => Thrift::Types::BYTE}},
+ I16S => {:type => Thrift::Types::LIST, :name => 'i16s', :element => {:type => Thrift::Types::I16}},
+ I32S => {:type => Thrift::Types::LIST, :name => 'i32s', :element => {:type => Thrift::Types::I32}},
+ I64S => {:type => Thrift::Types::LIST, :name => 'i64s', :element => {:type => Thrift::Types::I64}},
+ DOUBLES => {:type => Thrift::Types::LIST, :name => 'doubles', :element => {:type => Thrift::Types::DOUBLE}},
+ STRINGS => {:type => Thrift::Types::LIST, :name => 'strings', :element => {:type => Thrift::Types::STRING}},
+ MAPS => {:type => Thrift::Types::LIST, :name => 'maps', :element => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I16}, :value => {:type => Thrift::Types::I16}}},
+ LISTS => {:type => Thrift::Types::LIST, :name => 'lists', :element => {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I16}}},
+ SETS => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
+ HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => Hello}}
}
end