charlotte-ruby/impressionist — pull request #13 by georgmittendorfer (2011-11-10 14:11:14+00:00)
Title: Unique impressions

Hi,

I added support to capture only unique views. There are two ways to use this:

* In the controller it is possible to do something like (these are just examples - works for all table columns. Check out the tests.):

a. impressionist :unique => [:impressionable_type, :impressionable_id, :session_hash]
b. impressionist :unique => [:controller_name, :action_name, :session_hash]
c. impressionist :unique => [:session_hash]
d. impressionist :unique => [:controller_name, :impressionable_id, :session_hash]

a. Adds one impression per type/id/session.
b. Adds one impression per controller/action/session.
c. Adds one impression per session.
d. similar to a. in most cases (if controller_name is used for impressionable_type)

* The same can be done via the impressionist method, e.g.:

impressionist(impressionable, "some message", :unique => [:controller_name, :impressionable_id, :session_hash])

If you want I can add shortcuts for some unique option combinations, e.g. :session for [:impressionable_type, :impressionable_id, :session_hash].

Please review the code and let me know what you think - I am no ruby expert, feel free to criticize. I can change implementation and usage if you want me to. You can ignore my changes to Gemfile and database.yml, I needed them to make the code run on my machine.