blob: 2323770425a936b764fc678b85035a93fc525c70 [file] [log] [blame]
nnobleebebb7e2014-12-10 16:31:01 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
nnobleebebb7e2014-12-10 16:31:01 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
nnobleebebb7e2014-12-10 16:31:01 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
nnobleebebb7e2014-12-10 16:31:01 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
nnobleebebb7e2014-12-10 16:31:01 -080016 *
17 */
18
Nicolas "Pixel" Noble1ff52d52015-03-01 05:24:36 +010019#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
20#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
nnobleebebb7e2014-12-10 16:31:01 -080021
Yang Gao478568e2015-03-23 22:09:22 -070022#include "src/compiler/config.h"
murgatroid99b39ad702016-05-20 13:27:33 -070023#include "src/compiler/generator_helpers.h"
nnobleebebb7e2014-12-10 16:31:01 -080024#include "src/compiler/ruby_generator_string-inl.h"
25
26namespace grpc_ruby_generator {
27
Craig Tillerbaa14a92017-11-03 09:09:36 -070028inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
29 grpc::string* file_name_or_error) {
nnobleebebb7e2014-12-10 16:31:01 -080030 // Get output file name.
rsilvera081e3202014-12-16 15:57:35 -080031 static const unsigned proto_suffix_length = 6; // length of ".proto"
nnobleebebb7e2014-12-10 16:31:01 -080032 if (file->name().size() > proto_suffix_length &&
33 file->name().find_last_of(".proto") == file->name().size() - 1) {
Craig Tillerb5dcec52015-01-13 11:13:42 -080034 *file_name_or_error =
35 file->name().substr(0, file->name().size() - proto_suffix_length) +
Ken Payson5a2c9182016-07-26 17:15:08 -070036 "_services_pb.rb";
nnobleebebb7e2014-12-10 16:31:01 -080037 return true;
38 } else {
39 *file_name_or_error = "Invalid proto file name: must end with .proto";
40 return false;
41 }
42}
43
Yang Gao478568e2015-03-23 22:09:22 -070044inline grpc::string MessagesRequireName(
Craig Tillerbaa14a92017-11-03 09:09:36 -070045 const grpc::protobuf::FileDescriptor* file) {
Ken Payson5a2c9182016-07-26 17:15:08 -070046 return Replace(file->name(), ".proto", "_pb");
nnobleebebb7e2014-12-10 16:31:01 -080047}
48
murgatroid99b39ad702016-05-20 13:27:33 -070049// Get leading or trailing comments in a string. Comment lines start with "# ".
50// Leading detached comments are put in in front of leading comments.
51template <typename DescriptorType>
Craig Tillerbaa14a92017-11-03 09:09:36 -070052inline grpc::string GetRubyComments(const DescriptorType* desc, bool leading) {
murgatroid99b39ad702016-05-20 13:27:33 -070053 return grpc_generator::GetPrefixedComments(desc, leading, "#");
54}
55
nnobleebebb7e2014-12-10 16:31:01 -080056} // namespace grpc_ruby_generator
57
Nicolas "Pixel" Noble1ff52d52015-03-01 05:24:36 +010058#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H