|
|
@ -30,24 +30,6 @@ |
|
|
|
require 'grpc/generic/client_stub' |
|
|
|
require 'grpc/generic/client_stub' |
|
|
|
require 'grpc/generic/rpc_desc' |
|
|
|
require 'grpc/generic/rpc_desc' |
|
|
|
|
|
|
|
|
|
|
|
# Extend String to add a method underscore |
|
|
|
|
|
|
|
class String |
|
|
|
|
|
|
|
# creates a new string that is the underscore separate version of this one. |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# E.g, |
|
|
|
|
|
|
|
# PrintHTML -> print_html |
|
|
|
|
|
|
|
# AMethod -> a_method |
|
|
|
|
|
|
|
# AnRpc -> an_rpc |
|
|
|
|
|
|
|
def underscore |
|
|
|
|
|
|
|
word = dup |
|
|
|
|
|
|
|
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') |
|
|
|
|
|
|
|
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') |
|
|
|
|
|
|
|
word.tr!('-', '_') |
|
|
|
|
|
|
|
word.downcase! |
|
|
|
|
|
|
|
word |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GRPC contains the General RPC module. |
|
|
|
# GRPC contains the General RPC module. |
|
|
|
module GRPC |
|
|
|
module GRPC |
|
|
|
# Provides behaviour used to implement schema-derived service classes. |
|
|
|
# Provides behaviour used to implement schema-derived service classes. |
|
|
@ -55,6 +37,22 @@ module GRPC |
|
|
|
# Is intended to be used to support both client and server |
|
|
|
# Is intended to be used to support both client and server |
|
|
|
# IDL-schema-derived servers. |
|
|
|
# IDL-schema-derived servers. |
|
|
|
module GenericService |
|
|
|
module GenericService |
|
|
|
|
|
|
|
# creates a new string that is the underscore separate version of s. |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# E.g, |
|
|
|
|
|
|
|
# PrintHTML -> print_html |
|
|
|
|
|
|
|
# AMethod -> a_method |
|
|
|
|
|
|
|
# AnRpc -> an_rpc |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# @param s [String] the string to be converted. |
|
|
|
|
|
|
|
def self.underscore(s) |
|
|
|
|
|
|
|
s.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') |
|
|
|
|
|
|
|
s.gsub!(/([a-z\d])([A-Z])/, '\1_\2') |
|
|
|
|
|
|
|
s.tr!('-', '_') |
|
|
|
|
|
|
|
s.downcase! |
|
|
|
|
|
|
|
s |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
# Used to indicate that a name has already been specified |
|
|
|
# Used to indicate that a name has already been specified |
|
|
|
class DuplicateRpcName < StandardError |
|
|
|
class DuplicateRpcName < StandardError |
|
|
|
def initialize(name) |
|
|
|
def initialize(name) |
|
|
@ -171,7 +169,7 @@ module GRPC |
|
|
|
# Used define_method to add a method for each rpc_desc. Each method |
|
|
|
# Used define_method to add a method for each rpc_desc. Each method |
|
|
|
# calls the base class method for the given descriptor. |
|
|
|
# calls the base class method for the given descriptor. |
|
|
|
descs.each_pair do |name, desc| |
|
|
|
descs.each_pair do |name, desc| |
|
|
|
mth_name = name.to_s.underscore.to_sym |
|
|
|
mth_name = GenericService.underscore(name.to_s).to_sym |
|
|
|
marshal = desc.marshal_proc |
|
|
|
marshal = desc.marshal_proc |
|
|
|
unmarshal = desc.unmarshal_proc(:output) |
|
|
|
unmarshal = desc.unmarshal_proc(:output) |
|
|
|
route = "/#{route_prefix}/#{name}" |
|
|
|
route = "/#{route_prefix}/#{name}" |
|
|
@ -207,7 +205,7 @@ module GRPC |
|
|
|
# implemented. |
|
|
|
# implemented. |
|
|
|
def assert_rpc_descs_have_methods |
|
|
|
def assert_rpc_descs_have_methods |
|
|
|
rpc_descs.each_pair do |m, spec| |
|
|
|
rpc_descs.each_pair do |m, spec| |
|
|
|
mth_name = m.to_s.underscore.to_sym |
|
|
|
mth_name = GenericService.underscore(m.to_s).to_sym |
|
|
|
unless instance_methods.include?(mth_name) |
|
|
|
unless instance_methods.include?(mth_name) |
|
|
|
fail "#{self} does not provide instance method '#{mth_name}'" |
|
|
|
fail "#{self} does not provide instance method '#{mth_name}'" |
|
|
|
end |
|
|
|
end |
|
|
|