Sha256: 699e97e961b6cded76b0f21e25f939c6c4ed4d37c76567d67f7baa90f7f9d101

Contents?: true

Size: 978 Bytes

Versions: 2

Compression:

Stored size: 978 Bytes

Contents

require 'saorin/adapters/servers/base'
require 'reel'

module Saorin
  module Adapters
    module Servers
      class Reel < Base
        DEFAULT_HEADERS = {
          'Content-Type' => 'application/json'
        }.freeze

        attr_reader :server

        def initialize(handler, options = {}, &block)
          super handler, options

          @server = ::Reel::Server.supervise(options[:host], options[:port], &method(:process))
          trap(:INT) { @server.terminate; exit }
          sleep unless options[:nonblock]
        end

        def process(connection)
          while request = connection.request
            case request
            when ::Reel::Request
              response_body = process_request(request.body) if request.method.to_s.upcase == 'POST'
              response_body ||= ''
              request.respond :ok, DEFAULT_HEADERS.dup, response_body
            end
          end
        end
      end

      register :reel, Reel
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
saorin-0.2.0 lib/saorin/adapters/servers/reel.rb
saorin-0.1.4 lib/saorin/adapters/servers/reel.rb