Module: Candygram
- Defined in:
- lib/candygram.rb,
lib/candygram/utility.rb,
lib/candygram/wrapper.rb,
lib/candygram/delivery.rb,
lib/candygram/dispatch.rb,
lib/candygram/connection.rb
Defined Under Namespace
Modules: Delivery, Utility, Wrapper Classes: Dispatch
Constant Summary collapse
- DEFAULT_DATABASE =
'candygram'
- DEFAULT_QUEUE =
'candygram_queue'
- DEFAULT_QUEUE_SIZE =
10 MB
10 * 1024 * 1024
Class Method Summary collapse
-
.connection ⇒ Object
The MongoDB connection object.
-
.connection=(val) ⇒ Object
Accepts a new MongoDB connection, closing any current ones.
-
.create_queue(name = DEFAULT_QUEUE, size = DEFAULT_QUEUE_SIZE) ⇒ Object
Creates a new capped collection with the given name and cap size, and sets the indexes needed for efficient Candygram delivery.
-
.database ⇒ Object
The name of the Mongo database object.
-
.database=(val) ⇒ Object
Creates a Mongo database object with the given name and default options.
-
.db ⇒ Object
The Mongo database object.
-
.db=(val) ⇒ Object
Sets the Mongo database object.
-
.queue ⇒ Object
The delivery queue collection.
-
.queue=(val) ⇒ Object
Sets the delivery queue to an existing collection.
Class Method Details
.connection ⇒ Object
The MongoDB connection object. Creates a default connection to localhost if not explicitly told otherwise.
4 5 6 |
# File 'lib/candygram/connection.rb', line 4 def self.connection @connection ||= Mongo::Connection.new end |
.connection=(val) ⇒ Object
Accepts a new MongoDB connection, closing any current ones
9 10 11 12 |
# File 'lib/candygram/connection.rb', line 9 def self.connection=(val) @connection.close if @connection @connection = val end |
.create_queue(name = DEFAULT_QUEUE, size = DEFAULT_QUEUE_SIZE) ⇒ Object
Creates a new capped collection with the given name and cap size, and sets the indexes needed for efficient Candygram delivery.
56 57 58 59 60 61 62 63 |
# File 'lib/candygram/connection.rb', line 56 def self.create_queue(name=DEFAULT_QUEUE, size=DEFAULT_QUEUE_SIZE) @queue = db.create_collection(name, :capped => true, :size => size) # Make indexes here... @queue.create_index('deliver_at') @queue.create_index('locked') @queue.create_index('result') @queue end |
.database ⇒ Object
The name of the Mongo database object.
27 28 29 |
# File 'lib/candygram/connection.rb', line 27 def self.database db.name end |
.database=(val) ⇒ Object
Creates a Mongo database object with the given name and default options.
32 33 34 |
# File 'lib/candygram/connection.rb', line 32 def self.database=(val) self.db = Mongo::DB.new(val, connection) end |
.db ⇒ Object
The Mongo database object. If you just want the name, use #database instead.
15 16 17 |
# File 'lib/candygram/connection.rb', line 15 def self.db @db ||= Mongo::DB.new(DEFAULT_DATABASE, connection) end |
.db=(val) ⇒ Object
Sets the Mongo database object. Unless you want to pass specific options or bypass the Candygram connection object completely, it’s probably easier to use the #database= method and give it the name.
22 23 24 |
# File 'lib/candygram/connection.rb', line 22 def self.db=(val) @db = val end |
.queue ⇒ Object
The delivery queue collection. If not set, creates a capped collection with a default name of ‘candygram_queue’ and a default cap size of 100MB.
38 39 40 41 42 43 44 45 46 |
# File 'lib/candygram/connection.rb', line 38 def self.queue @queue or begin if db.collection_names.include?(DEFAULT_QUEUE) @queue = db[DEFAULT_QUEUE] else @queue = create_queue end end end |
.queue=(val) ⇒ Object
Sets the delivery queue to an existing collection. Assumes you know what you’re doing and have made all the proper indexes and such. If not, use the #create_queue method instead.
50 51 52 |
# File 'lib/candygram/connection.rb', line 50 def self.queue=(val) @queue = val end |