Class: Rack::Audit

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-audit/version.rb,
lib/rack-audit.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, name, uri) ⇒ Audit

Returns a new instance of Audit.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rack-audit.rb', line 13

def initialize(app, name, uri)
  @app   = app
  @queue = Queue.new
  @uri   = URI(uri)
  @host  = @uri.host
  @port  = @uri.port
  @name  = name

  @consumer = Thread.new do
    while true do
      body = @queue.pop
      begin
        post(@uri, body)
      rescue => e
        STDERR.puts e.inspect
      end
    end
  end
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



12
13
14
# File 'lib/rack-audit.rb', line 12

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/rack-audit.rb', line 12

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



12
13
14
# File 'lib/rack-audit.rb', line 12

def port
  @port
end

#queueObject (readonly)

Returns the value of attribute queue.



12
13
14
# File 'lib/rack-audit.rb', line 12

def queue
  @queue
end

Instance Method Details

#call(env) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/rack-audit.rb', line 33

def call(env)
  uuid = UUIDTools::UUID.random_create.to_s
  log_request(uuid, env)
  response = @app.call(env)
  log_response(uuid, response)
  response
end