Class: Almaz::Capture
- Inherits:
-
Object
- Object
- Almaz::Capture
- Defined in:
- lib/almaz.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #capture_keys(request) ⇒ Object
-
#initialize(app) ⇒ Capture
constructor
A new instance of Capture.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/almaz.rb', line 21 def call(env) begin request = Rack::Request.new(env) key = "almaz::#{Almaz.config[:session_variable]}::#{env['rack.session'][Almaz.config[:session_variable]]}" @r.rpush(key, capture_keys(request).to_json) @r.ltrim(key, 0, Almaz.config[:max_list_size] - 1) rescue => e puts "ALMAZ ERROR: #{e}" end @app.call(env) end |
#capture_keys(request) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/almaz.rb', line 34 def capture_keys(request) captured = {} Rack::Request.public_instance_methods(false).each do |request_method| captured[request_method] = request.send(request_method.to_sym) if Almaz.config[:capture_keys].include?(request_method.to_sym) end captured.merge!(:time => Time.now.to_s, :user_agent => request.env["HTTP_USER_AGENT"]) captured end |