Sha256: 6ecba25326685864d13d8222bd1be05e89543430fd7d0237279e7974ef53f280

Contents?: true

Size: 712 Bytes

Versions: 1

Compression:

Stored size: 712 Bytes

Contents

# encoding: utf-8

module Hyperdrive
  class Server
    def self.call(env)
      server.call(env)
    end

    private

    def self.server
      Rack::Builder.new do
        hyperdrive.resources.each do |key, resource|
          map resource.endpoint do
            use Rack::Runtime
            use Rack::Lint
            use Rack::Head
            run ->(env) {
              begin
                Hyperdrive::Response.new(env, resource).response
              rescue Hyperdrive::Errors::HTTPError => error
                [error.http_status_code, { 'Allow' => resource.allowed_methods.join(',') }, [error.message]]
              end
            }
          end
        end
      end.to_app
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hyperdrive-0.0.4 lib/hyperdrive/server.rb