Sha256: c06844376e67f75a8ff3ca042702b80192e71a6dfce41abdf637b4b07dbd7179

Contents?: true

Size: 832 Bytes

Versions: 14

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true

module RailwayIpc
  class Responder
    def self.respond(&block)
      @block = block
    end

    class << self
      attr_reader :block
    end

    def respond(request)
      RailwayIpc.logger.info(
        'Responding to request',
        protobuf: { type: request.class, data: request },
        feature: 'railway_ipc_request'
      )
      response = self.class.block.call(request)
      raise ResponseTypeError.new(response.class) unless response.is_a?(Google::Protobuf::MessageExts)

      response
    end

    class ResponseTypeError < StandardError
      def initialize(response_class)
        message = "`respond` block should return a Google Protobuf message that the corresponding client can handle, instead returned #{response_class}"
        super(message)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
railway-ipc-5.1.1 lib/railway_ipc/responder.rb
railway-ipc-5.1.0 lib/railway_ipc/responder.rb
railway-ipc-5.0.0 lib/railway_ipc/responder.rb
railway-ipc-4.0.1 lib/railway_ipc/responder.rb
railway-ipc-4.0.0 lib/railway_ipc/responder.rb
railway-ipc-3.0.0 lib/railway_ipc/responder.rb
railway-ipc-2.2.2 lib/railway_ipc/responder.rb
railway-ipc-2.2.1 lib/railway_ipc/responder.rb
railway-ipc-2.2.0 lib/railway_ipc/responder.rb
railway-ipc-2.1.0 lib/railway_ipc/responder.rb
railway-ipc-2.0.3 lib/railway_ipc/responder.rb
railway-ipc-2.0.2 lib/railway_ipc/responder.rb
railway-ipc-2.0.1 lib/railway_ipc/responder.rb
railway-ipc-2.0.0 lib/railway_ipc/responder.rb