Class: Bluecap::Identify
- Inherits:
-
Object
- Object
- Bluecap::Identify
- Defined in:
- lib/bluecap/handlers/identify.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#handle ⇒ Object
Returns an id to track a user in Bluecap, creating an id if one does not already exist.
-
#initialize(name) ⇒ Identify
constructor
Initialize an Identify handler.
Constructor Details
#initialize(name) ⇒ Identify
Initialize an Identify handler.
name - A String to uniquely identify the user from the source system.
10 11 12 |
# File 'lib/bluecap/handlers/identify.rb', line 10 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/bluecap/handlers/identify.rb', line 4 def name @name end |
Instance Method Details
#handle ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bluecap/handlers/identify.rb', line 24 def handle id = Bluecap.redis.hget('user.map', @name) return id.to_i if id id = Bluecap.redis.incr('user.ids') if Bluecap.redis.hsetnx('user.map', @name, id) return id else # Race condition, another process has set the id for this user. # The unused id shouldn't cause inaccuracies in reporting since # the position will be 0 in all bitsets across the system. return redis.hget('user.map', @name).to_i end end |