Skip to content
Snippets Groups Projects
Commit 583fe997 authored by temiola's avatar temiola Committed by Nicolas Noble
Browse files

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
parent 0f0a6bc4
No related branches found
No related tags found
No related merge requests found
...@@ -93,6 +93,8 @@ module Google::RPC ...@@ -93,6 +93,8 @@ module Google::RPC
# The Dsl verifies that the types in the descriptor have both the # The Dsl verifies that the types in the descriptor have both the
# unmarshal and marshal methods. # unmarshal and marshal methods.
attr_writer(:marshal_class_method, :unmarshal_class_method) attr_writer(:marshal_class_method, :unmarshal_class_method)
# This allows configuration of the service name.
attr_accessor(:service_name) attr_accessor(:service_name)
# Adds an RPC spec. # Adds an RPC spec.
...@@ -117,8 +119,8 @@ module Google::RPC ...@@ -117,8 +119,8 @@ module Google::RPC
end end
def inherited(subclass) def inherited(subclass)
# Each subclass should have distinct class variable with its own # Each subclass should have a distinct class variable with its own
# rpc_descs. # rpc_descs
subclass.rpc_descs.merge!(rpc_descs) subclass.rpc_descs.merge!(rpc_descs)
subclass.service_name = service_name subclass.service_name = service_name
end end
...@@ -227,8 +229,9 @@ module Google::RPC ...@@ -227,8 +229,9 @@ module Google::RPC
def self.included(o) def self.included(o)
o.extend(Dsl) o.extend(Dsl)
# Update to the use the name including module. This can be nil e,g. when # Update to the use the service name including module. Proivde a default
# modules are declared dynamically. # that can be nil e,g. when modules are declared dynamically.
return unless o.service_name.nil?
if o.name.nil? if o.name.nil?
o.service_name = 'GenericService' o.service_name = 'GenericService'
else else
......
...@@ -108,6 +108,39 @@ describe GenericService do ...@@ -108,6 +108,39 @@ describe GenericService do
expect(c.rpc_descs[:AnRpc]).to be_a(GRPC::RpcDesc) expect(c.rpc_descs[:AnRpc]).to be_a(GRPC::RpcDesc)
end 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 end
describe '#include' do describe '#include' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment