Class: Mongokit::Models::AutoIncrementCounter
- Inherits:
-
Object
- Object
- Mongokit::Models::AutoIncrementCounter
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/mongokit/models/auto_increment_counter.rb
Class Method Summary collapse
Class Method Details
.current_counter(options) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mongokit/models/auto_increment_counter.rb', line 28 def self.current_counter() record = Models::AutoIncrementCounter.find_by({ counter_model_name: [:model].collection_name, counter_field: [:attribute] }) return nil if record.nil? return record.counter if [:pattern].nil? return Formater.new.format(record.counter, ) end |
.find_or_create_with_seed(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mongokit/models/auto_increment_counter.rb', line 15 def self.find_or_create_with_seed() record = find_or_initialize_by({ counter_model_name: [:model].collection_name, counter_field: [:attribute] }) if record.new_record? record.counter = [:start] > 0 ? [:start] - 1 : [:start] end record.save end |