Class: Hyperdrive::Middleware::RequestMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/hyperdrive/middleware/request_method.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestMethod

Returns a new instance of RequestMethod.



6
7
8
# File 'lib/hyperdrive/middleware/request_method.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hyperdrive/middleware/request_method.rb', line 10

def call(env)
  http_request_method = env['REQUEST_METHOD']

  unless request_method_supported?(http_request_method)
    raise Hyperdrive::Errors::NotImplemented.new(http_request_method)
  end

  unless env['hyperdrive.resource'].request_method_allowed?(http_request_method)
    raise Hyperdrive::Errors::MethodNotAllowed.new(http_request_method)
  end

  @app.call(env)
end