Module: Notably::Notifiable
- Defined in:
- lib/notably/notifiable.rb
Instance Method Summary collapse
- #last_notification_read_at ⇒ Object
- #last_notification_read_at_key ⇒ Object
- #notification_key ⇒ Object
- #notifications ⇒ Object
- #notifications_since(time) ⇒ Object
- #read_notifications ⇒ Object
- #read_notifications! ⇒ Object
- #unread_notifications ⇒ Object
- #unread_notifications! ⇒ Object
Instance Method Details
#last_notification_read_at ⇒ Object
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_key ⇒ Object
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_key ⇒ Object
32 33 34 |
# File 'lib/notably/notifiable.rb', line 32 def notification_key "notably:notifications:#{self.class}:#{self.id}" end |
#notifications ⇒ Object
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_notifications ⇒ Object
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_notifications ⇒ Object
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 |