Skip to content

Instantly share code, notes, and snippets.

@coop
Created August 8, 2012 09:36
Show Gist options
  • Select an option

  • Save coop/3293783 to your computer and use it in GitHub Desktop.

Select an option

Save coop/3293783 to your computer and use it in GitHub Desktop.
client = Client.new RedisWhere.new
client.track event
class RedisWhere
def name
'redis'
end
def track message
$redis.rpush *message
end
end
class Client
attr_accessor :where
attr_writer :formatter
def initialize where
self.where = where
end
def formatter
@formatter ||= begin
format = {'redis' => 'Redis'}.fetch(where.name, 'Plain')
"Formatter::#{format}".constantize.new
end
end
def track event
where.track formatter.format(event)
end
end
module Formatter
class Redis
def format event
[event.payload[:user_id], event.to_json]
end
end
class Plain
def format event
"#{event.payload[:user_id]}: #{event.name}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment