Class: Vayacondios::Rack::ExtractMethods

Inherits:
Object
  • Object
show all
Includes:
Goliath::Rack::AsyncMiddleware
Defined in:
lib/vayacondios/server/rack/extract_methods.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
# File 'lib/vayacondios/server/rack/extract_methods.rb', line 6

def call(env)
  method_name = extract_method(env)
  super env.merge(vayacondios_method: method_name)
end

#extract_method(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vayacondios/server/rack/extract_methods.rb', line 11

def extract_method env        
  return unless env['REQUEST_METHOD']
  case env['REQUEST_METHOD'].upcase
  when 'PUT'    then
    if env.has_key? 'HTTP_X_METHOD'
      if env['HTTP_X_METHOD'].upcase == 'PATCH'
        :patch
      elsif env['HTTP_X_METHOD'].upcase == 'DELETE'
        :delete
      else
        :update
      end
    else
      :update
    end
  when 'GET'    then :show
  when 'POST'   then :create
  when 'PATCH'  then :patch
  when 'DELETE' then :delete
  else nil
  end
end