Skip to content

Commit

Permalink
Added the 'documentation' to the custom parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Cainã Costa committed Feb 4, 2011
1 parent 60d21c7 commit 94ca023
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.markdown
Expand Up @@ -49,7 +49,20 @@ You can also change the parser, to remove some of the fields (on the future, you

use Rack::Analytics::RequestLogger

Be sure to just use one of those, since they are mutually excludent (and `only` has a preference over `except`).
Be sure to just use one of those, since they are mutually excludent (and `only` has a preference over `except`). You can also create custom parsers, too, you just need to feed the parser with lambdas, like that:

require 'rack/analytics'

parser = Rack::Analytics::RequestParser.new

parser << lambda { |env, data| data['port'] = env['SERVER_PORT'] }
parser << lambda { |env, data| data['test'] = env['rack.test'] }

Rack::Analytics.parser = parser

use Rack::Analytics::RequestLogger

The env is a hash with all the parameters of the request, and the data is the fields that are saved on the MongoDB. Just be creative. You can use any kind of object, though, as long that they respond to `call` with two arguments.

## Notes on Patches/Pull Requests ##

Expand Down

0 comments on commit 94ca023

Please sign in to comment.