twirp-ruby icon indicating copy to clipboard operation
twirp-ruby copied to clipboard

For discussion: wrap generated service and client in module.

Open mnbbrown opened this issue 3 years ago • 0 comments

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.

mnbbrown avatar Feb 15 '22 12:02 mnbbrown