From 8f2596ad546451c50e48425e37eddc9195c5807e Mon Sep 17 00:00:00 2001 From: jfarrell Date: Thu, 29 Jan 2015 23:42:05 -0500 Subject: [PATCH] THRIFT-2961: Service inheritance does not work with namespaced Ruby code Client: rb Patch: Jan Brauer This closes #364 commit 111c4e77a78c1a82f526923f13534bb0027ef33f Author: Jan Brauer Date: 2015-01-29T22:01:26Z Make 'extends' work with 'rb:namespaced'. commit 34cab3d7c77bd5e8325ac4f30f1091429c35905e Author: Jan Brauer Date: 2015-01-29T22:25:03Z Add test for namespaced service extension --- compiler/cpp/src/generate/t_rb_generator.cc | 9 +++++-- lib/rb/Rakefile | 2 ++ lib/rb/spec/BaseService.thrift | 27 +++++++++++++++++++++ lib/rb/spec/ExtendedService.thrift | 25 +++++++++++++++++++ lib/rb/spec/namespaced_spec.rb | 5 ++++ 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 lib/rb/spec/BaseService.thrift create mode 100644 lib/rb/spec/ExtendedService.thrift diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc index ec7f8022f..9dac54a8b 100644 --- a/compiler/cpp/src/generate/t_rb_generator.cc +++ b/compiler/cpp/src/generate/t_rb_generator.cc @@ -753,8 +753,13 @@ void t_rb_generator::generate_service(t_service* tservice) { f_service_ << rb_autogen_comment() << endl << render_require_thrift(); if (tservice->get_extends() != NULL) { - f_service_ << "require '" << require_prefix_ << underscore(tservice->get_extends()->get_name()) - << "'" << endl; + if (namespaced_) { + f_service_ << "require '" << rb_namespace_to_path_prefix(tservice->get_extends()->get_program()->get_namespace("rb")) << underscore(tservice->get_extends()->get_name()) + << "'" << endl; + } else { + f_service_ << "require '" << require_prefix_ << underscore(tservice->get_extends()->get_name()) + << "'" << endl; + } } f_service_ << "require '" << require_prefix_ << underscore(program_name_) << "_types'" << endl diff --git a/lib/rb/Rakefile b/lib/rb/Rakefile index 8f1c4fec3..9dc8324dc 100644 --- a/lib/rb/Rakefile +++ b/lib/rb/Rakefile @@ -48,6 +48,8 @@ namespace :'gen-rb' do task :'namespaced_spec' do dir = File.dirname(__FILE__) + '/spec' sh THRIFT, '--gen', 'rb:namespaced', '-recurse', '-o', dir, "#{dir}/ThriftNamespacedSpec.thrift" + sh THRIFT, '--gen', 'rb:namespaced', '-recurse', '-o', dir, "#{dir}/BaseService.thrift" + sh THRIFT, '--gen', 'rb:namespaced', '-recurse', '-o', dir, "#{dir}/ExtendedService.thrift" end task :'flat_spec' do diff --git a/lib/rb/spec/BaseService.thrift b/lib/rb/spec/BaseService.thrift new file mode 100644 index 000000000..5c7d32a6c --- /dev/null +++ b/lib/rb/spec/BaseService.thrift @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +namespace rb Base + +struct Hello { + 1: string greeting = "hello world" +} + +service BaseService { + Hello greeting(1:bool english) +} diff --git a/lib/rb/spec/ExtendedService.thrift b/lib/rb/spec/ExtendedService.thrift new file mode 100644 index 000000000..1a6b705aa --- /dev/null +++ b/lib/rb/spec/ExtendedService.thrift @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +namespace rb Extended + +include "BaseService.thrift" + +service ExtendedService extends BaseService.BaseService { + void ping() +} diff --git a/lib/rb/spec/namespaced_spec.rb b/lib/rb/spec/namespaced_spec.rb index 8d4f88be1..31379d964 100644 --- a/lib/rb/spec/namespaced_spec.rb +++ b/lib/rb/spec/namespaced_spec.rb @@ -59,4 +59,9 @@ describe 'namespaced generation' do it "required an included file" do defined?(OtherNamespace::SomeEnum).should be_true end + + it "extended a service" do + require "extended/extended_service" + end + end