class Mongokit::Models::AutoIncrementCounter
Public Class Methods
current_counter(options)
click to toggle source
# File lib/mongokit/models/auto_increment_counter.rb, line 28 def self.current_counter(options) record = Models::AutoIncrementCounter.find_by({ counter_model_name: options[:model].collection_name, counter_field: options[:attribute] }) return nil if record.nil? return record.counter if options[:pattern].nil? return Formater.new.format(record.counter, options) end
find_or_create_with_seed(options)
click to toggle source
# File lib/mongokit/models/auto_increment_counter.rb, line 15 def self.find_or_create_with_seed(options) record = find_or_initialize_by({ counter_model_name: options[:model].collection_name, counter_field: options[:attribute] }) if record.new_record? record.counter = options[:start] > 0 ? options[:start] - 1 : options[:start] end record.save end