Class: RequestLog::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/request_log/data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, rack_response, app_time) ⇒ Data

Returns a new instance of Data.



5
6
7
8
9
10
11
# File 'lib/request_log/data.rb', line 5

def initialize(env, rack_response, app_time)
  self.env = env
  self.status = rack_response[0]
  self.headers = rack_response[1]
  self.response = rack_response[2]
  self.app_time = app_time
end

Instance Attribute Details

#app_timeObject

Returns the value of attribute app_time.



3
4
5
# File 'lib/request_log/data.rb', line 3

def app_time
  @app_time
end

#envObject

Returns the value of attribute env.



3
4
5
# File 'lib/request_log/data.rb', line 3

def env
  @env
end

#headersObject

Returns the value of attribute headers.



3
4
5
# File 'lib/request_log/data.rb', line 3

def headers
  @headers
end

#responseObject

Returns the value of attribute response.



3
4
5
# File 'lib/request_log/data.rb', line 3

def response
  @response
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/request_log/data.rb', line 3

def status
  @status
end

Class Method Details

.request_path(env) ⇒ Object



13
14
15
# File 'lib/request_log/data.rb', line 13

def self.request_path(env)
  env['PATH_INFO'] || env['REQUEST_PATH'] || "/"
end

Instance Method Details

#attributesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/request_log/data.rb', line 17

def attributes
  method       = env['REQUEST_METHOD']
  path         = self.class.request_path(env)
  {
    :method            => method,
    :path              => path, 
    :status            => status, 
    :time              => Time.now.utc,
    :runtime           => app_time,
    :ip                => env['REMOTE_ADDR'],
    :params            => params
  }
end

#paramsObject



31
32
33
34
# File 'lib/request_log/data.rb', line 31

def params
  # NOTE: It seems getting POST params with ::Rack::Request.new(env).params does not work well with Rails
  (env['action_controller.instance'] || ::Rack::Request.new(env)).params      
end