Class: Rasti::Web::ApiDoc::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rasti/web/api_doc/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.



6
7
8
# File 'lib/rasti/web/api_doc/request.rb', line 6

def initialize(env)
  @env = env
end

Instance Method Details

#form_paramsObject



34
35
36
# File 'lib/rasti/web/api_doc/request.rb', line 34

def form_params
  env['rack.request.form_hash'] || {}
end

#headersObject



38
39
40
41
42
43
# File 'lib/rasti/web/api_doc/request.rb', line 38

def headers
  headers = env.select { |k,v| k.start_with?('HTTP_') || k == 'CONTENT_TYPE' }
               .map { |k,v| [k.sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-'), v] }
               .sort
  Hash[headers]
end

#methodObject



10
11
12
# File 'lib/rasti/web/api_doc/request.rb', line 10

def method
  env['REQUEST_METHOD']
end

#path_infoObject



14
15
16
# File 'lib/rasti/web/api_doc/request.rb', line 14

def path_info
  env['PATH_INFO']
end

#query_paramsObject



30
31
32
# File 'lib/rasti/web/api_doc/request.rb', line 30

def query_params
  env['rack.request.query_hash'] || {}
end

#routeObject



18
19
20
21
22
23
24
# File 'lib/rasti/web/api_doc/request.rb', line 18

def route
  env['PATH_INFO'].dup.tap do |path_info|
    route_params.each do |name, value|
      path_info.sub! value, ":#{name}"
    end
  end
end

#route_paramsObject



26
27
28
# File 'lib/rasti/web/api_doc/request.rb', line 26

def route_params
  env['rack.request.route_params'] || {}
end