Class: Redde::Presence::View
- Inherits:
-
Object
- Object
- Redde::Presence::View
- Defined in:
- app/models/redde/presence/view.rb
Constant Summary collapse
- TTL =
15
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(obj, user_id) ⇒ View
constructor
A new instance of View.
- #key ⇒ Object
- #view ⇒ Object
Constructor Details
#initialize(obj, user_id) ⇒ View
Returns a new instance of View.
7 8 9 10 |
# File 'app/models/redde/presence/view.rb', line 7 def initialize(obj, user_id) @obj = obj @user_id = user_id end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
4 5 6 |
# File 'app/models/redde/presence/view.rb', line 4 def obj @obj end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
4 5 6 |
# File 'app/models/redde/presence/view.rb', line 4 def user_id @user_id end |
Class Method Details
.viewers_of(obj) ⇒ Object
12 13 14 15 16 |
# File 'app/models/redde/presence/view.rb', line 12 def self.viewers_of(obj) Redis.current.keys("#{obj.class.name}:#{obj.id}:*").map do |key| key.split(':').last.to_i end end |
Instance Method Details
#key ⇒ Object
23 24 25 |
# File 'app/models/redde/presence/view.rb', line 23 def key "#{obj.class.name}:#{obj.id}:#{user_id}" end |
#view ⇒ Object
18 19 20 21 |
# File 'app/models/redde/presence/view.rb', line 18 def view Redis.current.set(key, 1) Redis.current.expire(key, TTL) end |