Module: Rack::Analytics

Defined in:
lib/rack/analytics.rb,
lib/rack/analytics/version.rb,
lib/rack/analytics/request_logger.rb,
lib/rack/analytics/request_parser.rb,
lib/generators/rack/analytics/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: RequestLogger, RequestParser

Constant Summary collapse

VERSION =
"0.0.3"
@@queue =
Queue.new
@@parser =
RequestParser.new
@@db_name =
'rack-analytics'
@@db =
Mongo::Connection.new.db(@@db_name)

Class Method Summary collapse

Class Method Details

.finish!Object



30
31
32
33
34
35
36
# File 'lib/rack/analytics.rb', line 30

def self.finish!
  queue << nil
  thread.join
  @@thread = nil

  thread
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



38
39
40
# File 'lib/rack/analytics.rb', line 38

def self.setup
  yield self
end

.threadObject



22
23
24
25
26
27
28
# File 'lib/rack/analytics.rb', line 22

def self.thread
  @@thread ||= Thread.new do
    while env = queue.pop
      db['views'].insert parser.parse(env).data
    end
  end
end