Class: Redde::Presence::View

Inherits:
Object
  • Object
show all
Defined in:
app/models/redde/presence/view.rb

Constant Summary collapse

TTL =
15

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#objObject (readonly)

Returns the value of attribute obj.



4
5
6
# File 'app/models/redde/presence/view.rb', line 4

def obj
  @obj
end

#user_idObject (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

#keyObject



23
24
25
# File 'app/models/redde/presence/view.rb', line 23

def key
  "#{obj.class.name}:#{obj.id}:#{user_id}"
end

#viewObject



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