Class: Mongoid::Publishable::Queue

Inherits:
Array
  • Object
show all
Defined in:
lib/mongoid/publishable/queue.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(session = nil) ⇒ Object

loads the queue from the session



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mongoid/publishable/queue.rb', line 8

def self.load(session = nil)
  # create a new queue
  queue = new
  # if there was no existing queue, return new
  return queue unless session
  # create our contents
  contents = session.split("\n").map do |data|
    UnpublishedObject.deserialize_from_session(data)
  end
  # add into the queue
  queue.replace(contents)
end

Instance Method Details

#dumpObject

creates a string containing the data of the queue



32
33
34
35
36
# File 'lib/mongoid/publishable/queue.rb', line 32

def dump
  map do |model|
    model.serialize_for_session
  end.join("\n")
end

#publish_via(publisher) ⇒ Object

publishes all the objects on the queue to this user



22
23
24
25
26
27
28
29
# File 'lib/mongoid/publishable/queue.rb', line 22

def publish_via(publisher)
  remaining = delete_if do |model|
    model.publish_via!(publisher)
    model.published?
  end
  # replaces the contents with the remaining models
  replace(remaining)
end

#push(*models) ⇒ Object Also known as: <<

adds a new object to the queue



39
40
41
42
43
44
45
46
# File 'lib/mongoid/publishable/queue.rb', line 39

def push(*models)
  # map each item to an unpublished object
  models = Array(models).map do |model|
    UnpublishedObject.new(model: model)
  end
  # add them to the array
  super(*models)
end