lib/protobuf/compiler/compiler.rb in ruby_protobuf-0.3.0 vs lib/protobuf/compiler/compiler.rb in ruby_protobuf-0.3.2
- old
+ new
@@ -13,34 +13,34 @@
create_message proto_file, proto_dir, out_dir, file_create
create_rpc proto_file, proto_dir, out_dir, file_create
end
def create_message(proto_file, proto_dir='.', out_dir='.', file_create=true)
- rb_file = "#{out_dir}/#{proto_file.sub(/\.proto$/, '.rb')}"
+ out_dir.sub! %r{/$}, ''
+ proto_dir.sub! %r{/$}, ''
+ rb_file =
+ if proto_file =~ %r{^/}
+ then "#{out_dir}/#{proto_file.split('/').last.sub(/\.proto$/, '.pb.rb')}"
+ else "#{out_dir}/#{proto_file.sub(/\.proto$/, '.pb.rb')}" end
proto_path = validate_existence proto_file, proto_dir
- message_visitor = Protobuf::Visitor::CreateMessageVisitor.new proto_dir, out_dir
+ message_visitor = Protobuf::Visitor::CreateMessageVisitor.new proto_file, proto_dir, out_dir
File.open proto_path, 'r' do |file|
message_visitor.visit Protobuf::ProtoParser.new.parse(file)
end
- if file_create
- puts "#{rb_file} writing..."
- FileUtils.mkpath File.dirname(rb_file)
- File.open(rb_file, 'w') {|f| f.write message_visitor.to_s}
- else
- message_visitor.to_s
- end
+ message_visitor.create_files rb_file, out_dir, file_create
end
def create_rpc(proto_file, proto_dir='.', out_dir='.', file_create=true)
- rb_file = "#{out_dir}/#{proto_file.sub(/\.proto$/, '.rb')}"
+ message_file = "#{out_dir}/#{proto_file.sub(/\.proto$/, '.pb.rb')}"
+ out_dir = "#{out_dir}/#{File.dirname proto_file}"
proto_path = validate_existence proto_file, proto_dir
- rpc_visitor = Protobuf::Visitor::CreateRpcVisitor.new# proto_dir, out_dir
+ rpc_visitor = Protobuf::Visitor::CreateRpcVisitor.new
File.open proto_path, 'r' do |file|
rpc_visitor.visit Protobuf::ProtoParser.new.parse(file)
end
- rpc_visitor.create_files rb_file, out_dir, file_create
+ rpc_visitor.create_files message_file, out_dir, file_create
end
def validate_existence(path, base_dir)
if File.exist? path
elsif File.exist?(path = "#{base_dir or '.'}/#{path}")