THRIFT-2961: Service inheritance does not work with namespaced Ruby code

Client: rb
Patch: Jan Brauer

This closes #364

commit 111c4e77a78c1a82f526923f13534bb0027ef33f
Author: Jan Brauer <jan@jimdo.com>
Date: 2015-01-29T22:01:26Z
Make 'extends' work with 'rb:namespaced'.
commit 34cab3d7c77bd5e8325ac4f30f1091429c35905e
Author: Jan Brauer <jan@jimdo.com>
Date: 2015-01-29T22:25:03Z
Add test for namespaced service extension
This commit is contained in:
jfarrell 2015-01-29 23:42:05 -05:00
parent 4e16718e99
commit 8f2596ad54
5 changed files with 66 additions and 2 deletions

View File

@ -753,8 +753,13 @@ void t_rb_generator::generate_service(t_service* tservice) {
f_service_ << rb_autogen_comment() << endl << render_require_thrift(); f_service_ << rb_autogen_comment() << endl << render_require_thrift();
if (tservice->get_extends() != NULL) { if (tservice->get_extends() != NULL) {
f_service_ << "require '" << require_prefix_ << underscore(tservice->get_extends()->get_name()) if (namespaced_) {
<< "'" << endl; 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 f_service_ << "require '" << require_prefix_ << underscore(program_name_) << "_types'" << endl

View File

@ -48,6 +48,8 @@ namespace :'gen-rb' do
task :'namespaced_spec' do task :'namespaced_spec' do
dir = File.dirname(__FILE__) + '/spec' 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}/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 end
task :'flat_spec' do task :'flat_spec' do

View File

@ -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)
}

View File

@ -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()
}

View File

@ -59,4 +59,9 @@ describe 'namespaced generation' do
it "required an included file" do it "required an included file" do
defined?(OtherNamespace::SomeEnum).should be_true defined?(OtherNamespace::SomeEnum).should be_true
end end
it "extended a service" do
require "extended/extended_service"
end
end end