Class: MongoidAutoInc::Incrementor::Sequence
- Inherits:
-
Object
- Object
- MongoidAutoInc::Incrementor::Sequence
- Defined in:
- lib/mongoid_auto_inc/incrementor.rb
Instance Method Summary collapse
- #inc ⇒ Object
-
#initialize(sequence, collection_name, seed) ⇒ Sequence
constructor
A new instance of Sequence.
- #set(number) ⇒ Object
Constructor Details
#initialize(sequence, collection_name, seed) ⇒ Sequence
Returns a new instance of Sequence.
6 7 8 9 10 |
# File 'lib/mongoid_auto_inc/incrementor.rb', line 6 def initialize(sequence, collection_name, seed) @sequence = sequence.to_s @collection = collection_name.to_s exists? || create(seed) end |
Instance Method Details
#inc ⇒ Object
12 13 14 |
# File 'lib/mongoid_auto_inc/incrementor.rb', line 12 def inc update_number_with("$inc" => { "number" => 1 }) end |
#set(number) ⇒ Object
16 17 18 |
# File 'lib/mongoid_auto_inc/incrementor.rb', line 16 def set(number) update_number_with("$set" => { "number" => number }) end |