Class: AppleShove::NotificationQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_shove/notification_queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, redis = Redis.new) ⇒ NotificationQueue

Returns a new instance of NotificationQueue.



7
8
9
10
# File 'lib/apple_shove/notification_queue.rb', line 7

def initialize(key, redis = Redis.new)
  @redis = redis
  @key = key
end

Instance Method Details

#add(notification) ⇒ Object



12
13
14
# File 'lib/apple_shove/notification_queue.rb', line 12

def add(notification)
  @redis.rpush @key, notification.to_json
end

#getObject



16
17
18
19
# File 'lib/apple_shove/notification_queue.rb', line 16

def get
  element = @redis.lpop @key
  element ? Notification.parse(element) : nil
end

#sizeObject



21
22
23
# File 'lib/apple_shove/notification_queue.rb', line 21

def size
  @redis.llen @key
end