aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar temiola <temiola@google.com>2015-01-08 09:41:31 -0800
committerGravatar Tim Emiola <temiola@google.com>2015-01-08 13:44:59 -0800
commit16be8a4a90f8b3d2fd83e33a7c379b1f6505baa4 (patch)
treefd704510dadeb063100e3e746bd1ede9e3eb9c79 /src
parent6e48a4258ac4958e4392d8091d16267c1c1c2320 (diff)
Updates service.rb to ensure that the DSL specified service name is not overridden
Change on 2015/01/08 by temiola <temiola@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=83525675
Diffstat (limited to 'src')
-rw-r--r--src/ruby/lib/grpc/generic/service.rb11
-rw-r--r--src/ruby/spec/generic/service_spec.rb33
2 files changed, 40 insertions, 4 deletions
diff --git a/src/ruby/lib/grpc/generic/service.rb b/src/ruby/lib/grpc/generic/service.rb
index 6a4356fab9..f3fe638fce 100644
--- a/src/ruby/lib/grpc/generic/service.rb
+++ b/src/ruby/lib/grpc/generic/service.rb
@@ -93,6 +93,8 @@ module Google::RPC
# The Dsl verifies that the types in the descriptor have both the
# unmarshal and marshal methods.
attr_writer(:marshal_class_method, :unmarshal_class_method)
+
+ # This allows configuration of the service name.
attr_accessor(:service_name)
# Adds an RPC spec.
@@ -117,8 +119,8 @@ module Google::RPC
end
def inherited(subclass)
- # Each subclass should have distinct class variable with its own
- # rpc_descs.
+ # Each subclass should have a distinct class variable with its own
+ # rpc_descs
subclass.rpc_descs.merge!(rpc_descs)
subclass.service_name = service_name
end
@@ -227,8 +229,9 @@ module Google::RPC
def self.included(o)
o.extend(Dsl)
- # Update to the use the name including module. This can be nil e,g. when
- # modules are declared dynamically.
+ # Update to the use the service name including module. Proivde a default
+ # that can be nil e,g. when modules are declared dynamically.
+ return unless o.service_name.nil?
if o.name.nil?
o.service_name = 'GenericService'
else
diff --git a/src/ruby/spec/generic/service_spec.rb b/src/ruby/spec/generic/service_spec.rb
index dc921d8934..a8e0c6f52f 100644
--- a/src/ruby/spec/generic/service_spec.rb
+++ b/src/ruby/spec/generic/service_spec.rb
@@ -108,6 +108,39 @@ describe GenericService do
expect(c.rpc_descs[:AnRpc]).to be_a(GRPC::RpcDesc)
end
+ it 'adds a default service name' do
+ c = Class.new do
+ include GenericService
+ end
+ expect(c.service_name).to eq('GenericService')
+ end
+
+ it 'adds a default service name to subclasses' do
+ base = Class.new do
+ include GenericService
+ end
+ c = Class.new(base) do
+ end
+ expect(c.service_name).to eq('GenericService')
+ end
+
+ it 'adds the specified service name' do
+ c = Class.new do
+ include GenericService
+ self.service_name = 'test.service.TestService'
+ end
+ expect(c.service_name).to eq('test.service.TestService')
+ end
+
+ it 'adds the specified service name to subclasses' do
+ base = Class.new do
+ include GenericService
+ self.service_name = 'test.service.TestService'
+ end
+ c = Class.new(base) do
+ end
+ expect(c.service_name).to eq('test.service.TestService')
+ end
end
describe '#include' do