Module: Notably::Notifiable

Defined in:
lib/notably/notifiable.rb

Instance Method Summary collapse

Instance Method Details

#last_notification_read_atObject



28
29
30
# File 'lib/notably/notifiable.rb', line 28

def last_notification_read_at
  Notably.config.redis.get(last_notification_read_at_key).to_i
end

#last_notification_read_at_keyObject



36
37
38
# File 'lib/notably/notifiable.rb', line 36

def last_notification_read_at_key
  "notably:last_read_at:#{self.class}:#{self.id}"
end

#notification_keyObject



32
33
34
# File 'lib/notably/notifiable.rb', line 32

def notification_key
  "notably:notifications:#{self.class}:#{self.id}"
end

#notificationsObject



4
5
6
# File 'lib/notably/notifiable.rb', line 4

def notifications
  parse_notifications(Notably.config.redis.zrevrangebyscore(notification_key, Time.now.to_i, 0))
end

#notifications_since(time) ⇒ Object



8
9
10
# File 'lib/notably/notifiable.rb', line 8

def notifications_since(time)
  parse_notifications(Notably.config.redis.zrevrangebyscore(notification_key, Time.now.to_i, time.to_i))
end

#read_notificationsObject



20
21
22
# File 'lib/notably/notifiable.rb', line 20

def read_notifications
  parse_notifications(Notably.config.redis.zrevrangebyscore(notification_key, last_notification_read_at, 0))
end

#read_notifications!Object



24
25
26
# File 'lib/notably/notifiable.rb', line 24

def read_notifications!
  parse_notifications(Notably.config.redis.set(last_notification_read_at_key, Time.now.to_i))
end

#unread_notificationsObject



12
13
14
# File 'lib/notably/notifiable.rb', line 12

def unread_notifications
  notifications_since(last_notification_read_at)
end

#unread_notifications!Object



16
17
18
# File 'lib/notably/notifiable.rb', line 16

def unread_notifications!
  notifications_since(Notably.config.redis.getset(last_notification_read_at_key, Time.now.to_i))
end