Sha256: e0c9adf2234219cda05892484122f15e896514f99e7ea037b7c0b61f1aa32417

Contents?: true

Size: 684 Bytes

Versions: 7

Compression:

Stored size: 684 Bytes

Contents

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

    def self.block
      @block
    end

    def respond(request)
      RailwayIpc.logger.info(request, "Responding to 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

7 entries across 7 versions & 1 rubygems

Version Path
railway-ipc-0.1.7 lib/railway_ipc/responder.rb
railway-ipc-0.1.6 lib/railway_ipc/responder.rb
railway-ipc-0.1.5 lib/railway_ipc/responder.rb
railway-ipc-0.1.4 lib/railway_ipc/responder.rb
railway-ipc-0.1.3 lib/railway_ipc/responder.rb
railway-ipc-0.1.2 lib/railway_ipc/responder.rb
railway-ipc-0.1.1 lib/railway_ipc/responder.rb