Created
April 28, 2014 22:12
-
-
Save moofish32/11385539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/core_ext' | |
require 'rails/all' | |
class Helpers | |
def self.map_type type | |
case type | |
when /boolean/ | |
'bool' | |
when /java.lang.int/ | |
'int32' | |
when /java.lang.long/ | |
'int64' | |
else | |
'string' | |
end | |
end | |
def self.print_with_indent(string, tabs) | |
puts "\t" * tabs + string | |
end | |
end | |
klass = <insert_case_class_name_here> | |
package, message = klass.java_class.name.split('$') | |
puts message; puts klass.java_class.name.split('$') | |
message_def = "message #{message.camelize} {" | |
package_def = "java_package = '#{package}'" | |
field_map = klass.java_class.declared_fields.inject({}) do |r, m| | |
r[m.name.underscore] = m | |
r | |
end | |
proto_msg_fields = [] | |
field_map.each_with_index do |v,i| | |
type = Helpers.map_type (v[1].to_s) | |
proto_msg_fields << "required #{type} #{v[0]} = #{proto_msg_fields.size};" | |
end | |
puts package_def | |
puts | |
puts message_def | |
proto_msg_fields.each{|f| Helpers.print_with_indent(f,1)} | |
puts "}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment