Class: MongoidAutoInc::Incrementor::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid_auto_inc/incrementor.rb

Instance Method Summary collapse

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

#incObject



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