1/*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * 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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * 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.
16 *
17 */
18
19#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
20#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
21
22#include "src/compiler/config.h"
23#include "src/compiler/generator_helpers.h"
24#include "src/compiler/ruby_generator_string-inl.h"
25
26namespace grpc_ruby_generator {
27
28inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
29 grpc::string* file_name_or_error) {
30 // Get output file name.
31 static const unsigned proto_suffix_length = 6; // length of ".proto"
32 if (file->name().size() > proto_suffix_length &&
33 file->name().find_last_of(".proto") == file->name().size() - 1) {
34 *file_name_or_error =
35 file->name().substr(0, file->name().size() - proto_suffix_length) +
36 "_services_pb.rb";
37 return true;
38 } else {
39 *file_name_or_error = "Invalid proto file name: must end with .proto";
40 return false;
41 }
42}
43
44inline grpc::string MessagesRequireName(
45 const grpc::protobuf::FileDescriptor* file) {
46 return Replace(file->name(), ".proto", "_pb");
47}
48
49// Get leading or trailing comments in a string. Comment lines start with "# ".
50// Leading detached comments are put in front of leading comments.
51template <typename DescriptorType>
52inline grpc::string GetRubyComments(const DescriptorType* desc, bool leading) {
53 return grpc_generator::GetPrefixedComments(desc, leading, "#");
54}
55
56} // namespace grpc_ruby_generator
57
58#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
59