<commit_before>module Protobuf
  module Rpc
    class Generator
      def initialize(mod)
        @mutex = Mutex.new
        @services = {}
        @clients = {}
        @module = mod
      end

      def generate(service, with: [])
        @mutex.synchronize do
          define_service_class(service)
          with.each { |m| @services[service].define_rpc(m) }
          define_client_class(service)
        end
        self
      end

      private
      def define_service_class(service)
        @module.const_set(:Services, Module.new) unless @module.const_defined?(:Services, false)
        @services[service] ||= if @module::Services.const_defined?(service, false)
                                 @module::Services.const_get(service, false)
                               else
                                 @module::Services.const_set(service, Class.new(Protobuf::Rpc::Services::Base))
                               end
      end

      def define_client_class(service)
        @module.const_set(:Clients, Module.new) unless @module.const_defined?(:Clients)
        @clients[service] ||= if @module::Clients.const_defined?(service, false)
                                @module::Clients.const_get(service, false)
                              else
                                @module::Clients.const_set(service, Class.new(Protobuf::Rpc::Clients::Base))
                              end
        @services[service].rpcs.keys.each { |m| @clients[service].implement_rpc(m) }
      end
    end
  end
end<commit_msg>Try to resolve autoloading problem<commit_after>module Protobuf
  module Rpc
    class Generator
      def initialize(mod)
        @mutex = Mutex.new
        @services = {}
        @clients = {}
        @module = mod
      end

      def generate(service, with: [])
        @mutex.synchronize do
          define_service_class(service)
          with.each { |m| @services[service].define_rpc(m) }
          define_client_class(service)
        end
        self
      end

      private
      def define_service_class(service)
        @module.const_set(:Services, Module.new) unless @module.const_defined?(:Services, false)
        @services[service] ||= "#{@module}::Services::#{service}".safe_constantize ||
            @module::Services.const_set(service, Class.new(Protobuf::Rpc::Services::Base))
      end

      def define_client_class(service)
        @module.const_set(:Clients, Module.new) unless @module.const_defined?(:Clients)
        @clients[service] ||= "#{@module}::Clients::#{service}".safe_constantize ||
            @module::Clients.const_set(service, Class.new(Protobuf::Rpc::Clients::Base))
        @services[service].rpcs.keys.each { |m| @clients[service].implement_rpc(m) }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1184593023255814, 'fraction_numerical': 0.0, 'mean_word_length': 2.1753171856978084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6412202', 'n_tokens_mistral': 791, 'n_tokens_neox': 786, 'n_words': 131}