Class: Rack::MethodOverride4All

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/methodoverride_4_all.rb

Constant Summary collapse

HTTP_METHODS =
%w(GET HEAD PUT POST DELETE OPTIONS)
METHOD_OVERRIDE_PARAM_KEY =
'_method'
HTTP_METHOD_OVERRIDE_HEADER =
'HTTP_X_HTTP_METHOD_OVERRIDE'

Instance Method Summary collapse

Constructor Details

#initialize(app, overridable = %w(GET POST)) ⇒ MethodOverride4All

Returns a new instance of MethodOverride4All.



7
8
9
10
# File 'lib/rack/methodoverride_4_all.rb', line 7

def initialize(app, overridable = %w(GET POST))
  @app         = app
  @overridable = HTTP_METHODS & overridable.map(&:to_s).map(&:upcase)
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
# File 'lib/rack/methodoverride_4_all.rb', line 12

def call(env)
  override_method(env) if (@overridable.include?(env['REQUEST_METHOD']))
  @app.call(env)
end