Module: GRPC::GenericService

Overview

Provides behaviour used to implement schema-derived service classes.

Is intended to be used to support both client and server IDL-schema-derived servers.

Defined Under Namespace

Modules: Dsl Classes: DuplicateRpcName

Class Method Summary collapse

Class Method Details

.included(o) ⇒ Object


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'src/ruby/lib/grpc/generic/service.rb', line 194

def self.included(o)
  o.extend(Dsl)
  # Update to the use the service name including module. Provide 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
    modules = o.name.split('::')
    if modules.length > 2
      o.service_name = modules[modules.length - 2]
    else
      o.service_name = modules.first
    end
  end
end

.underscore(s) ⇒ Object

creates a new string that is the underscore separate version of s.

E.g, PrintHTML -> print_html AMethod -> a_method AnRpc -> an_rpc

Parameters:

  • s (String)

    the string to be converted.


33
34
35
36
37
38
39
40
# File 'src/ruby/lib/grpc/generic/service.rb', line 33

def self.underscore(s)
  s = +s # Avoid mutating the argument, as it might be frozen.
  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