Permalink
Browse files

use with_indifferent_access for options

  • Loading branch information...
1 parent 91682d6 commit c0faecd2c2663a4a258e7974d5dbf29ee7693d68 @jacquescrocker committed Jun 3, 2011
Showing with 16 additions and 9 deletions.
  1. +2 −1 .gitignore
  2. +1 −0 aarrr.gemspec
  3. +13 −8 lib/aarrr/session.rb
View
@@ -1,2 +1,3 @@
.rvmrc
-ideas/
+ideas/
+pkg/aarrr-0.0.1.gem
View
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "rack", ">= 1.2.2"
s.add_runtime_dependency "mongo", ">= 1.3.1"
+ s.add_runtime_dependency "active_support", ">= 3.0.0"
s.add_development_dependency "rspec", ">= 2.0"
end
View
@@ -1,5 +1,7 @@
# encoding: utf-8
+require "active_support/hash/indifferent_access"
+
module AARRR
# an AARR session is used to identify a particular user in order to track events
@@ -35,23 +37,26 @@ def save(response)
# track event name
def track!(event_name, options = {})
+ options = options.with_indifferent_access
# add event tracking
result = AARRR.events.insert({
"aarrr_user_id" => self.id,
"event_name" => event_name,
- "event_type" => options[:event_type],
- "in_progress" => options[:in_progress] || false,
- "data" => options[:data],
- "revenue" => options[:revenue],
- "referral_code" => options[:referral_code]
+ "event_type" => options["event_type"],
+ "in_progress" => options["in_progress"] || false,
+ "data" => options["data"],
+ "revenue" => options["revenue"],
+ "referral_code" => options["referral_code"]
})
# update user with last updated time
+ user_updates = {
+ "last_event_at" => Time.now.getutc
+ }
+ user_updates["user_id"] = options["user_id"] if options["user_id"]
update({
- "$set" => {
- "last_event_at" => Time.now.getutc
- }
+ "$set" => user_updates
})
result

0 comments on commit c0faecd

Please sign in to comment.