twirp-ruby
twirp-ruby copied to clipboard
For discussion: wrap generated service and client in module.
I'm looking to wrap the generated service and client in a module to better support projects that use Zeitwerk (i.e. rails). This will allow the zeitwerk to work with a simple custom inflector like:
class Inflector < Zeitwerk::Inflector
def camelize(basename, abspath)
if basename =~ /\A(.*)_twirp/
super($1, abspath) + "Service"
else
super
end
end
end
It also brings the style in line with what grpc-tools generates.
For an example service the twirp file generated would be:
# Code generated by protoc-gen-twirp_ruby 1.9.0, DO NOT EDIT.
require 'twirp'
require_relative 'tracer_pb.rb'
module TracerService
class Service < Twirp::Service
package 'tracer.v1'
service 'TracerService'
rpc :Bullet, BulletRequest, BulletResponse, :ruby_method => :bullet
end
class Client < Twirp::Client
client_for Service
end
end
This would obviously be a breaking change.