nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Nicolas "Pixel" Noble | 1ff52d5 | 2015-03-01 05:24:36 +0100 | [diff] [blame] | 19 | #ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H |
| 20 | #define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 21 | |
Yang Gao | 478568e | 2015-03-23 22:09:22 -0700 | [diff] [blame] | 22 | #include "src/compiler/config.h" |
murgatroid99 | b39ad70 | 2016-05-20 13:27:33 -0700 | [diff] [blame] | 23 | #include "src/compiler/generator_helpers.h" |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 24 | #include "src/compiler/ruby_generator_string-inl.h" |
| 25 | |
| 26 | namespace grpc_ruby_generator { |
| 27 | |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 28 | inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file, |
| 29 | grpc::string* file_name_or_error) { |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 30 | // Get output file name. |
rsilvera | 081e320 | 2014-12-16 15:57:35 -0800 | [diff] [blame] | 31 | static const unsigned proto_suffix_length = 6; // length of ".proto" |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 32 | if (file->name().size() > proto_suffix_length && |
| 33 | file->name().find_last_of(".proto") == file->name().size() - 1) { |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 34 | *file_name_or_error = |
| 35 | file->name().substr(0, file->name().size() - proto_suffix_length) + |
Ken Payson | 5a2c918 | 2016-07-26 17:15:08 -0700 | [diff] [blame] | 36 | "_services_pb.rb"; |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 37 | return true; |
| 38 | } else { |
| 39 | *file_name_or_error = "Invalid proto file name: must end with .proto"; |
| 40 | return false; |
| 41 | } |
| 42 | } |
| 43 | |
Yang Gao | 478568e | 2015-03-23 22:09:22 -0700 | [diff] [blame] | 44 | inline grpc::string MessagesRequireName( |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 45 | const grpc::protobuf::FileDescriptor* file) { |
Ken Payson | 5a2c918 | 2016-07-26 17:15:08 -0700 | [diff] [blame] | 46 | return Replace(file->name(), ".proto", "_pb"); |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 47 | } |
| 48 | |
murgatroid99 | b39ad70 | 2016-05-20 13:27:33 -0700 | [diff] [blame] | 49 | // Get leading or trailing comments in a string. Comment lines start with "# ". |
| 50 | // Leading detached comments are put in in front of leading comments. |
| 51 | template <typename DescriptorType> |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 52 | inline grpc::string GetRubyComments(const DescriptorType* desc, bool leading) { |
murgatroid99 | b39ad70 | 2016-05-20 13:27:33 -0700 | [diff] [blame] | 53 | return grpc_generator::GetPrefixedComments(desc, leading, "#"); |
| 54 | } |
| 55 | |
nnoble | ebebb7e | 2014-12-10 16:31:01 -0800 | [diff] [blame] | 56 | } // namespace grpc_ruby_generator |
| 57 | |
Nicolas "Pixel" Noble | 1ff52d5 | 2015-03-01 05:24:36 +0100 | [diff] [blame] | 58 | #endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H |