module MongoidAutoIncrement::ClassMethods
Public Instance Methods
auto_increment(name, options = {})
click to toggle source
# File lib/mongoid_auto_increment.rb, line 7 def auto_increment(name, options = {}) field name, type: Integer unless defined? @@incrementor @@incrementor = MongoidAutoIncrement::Incrementor.new end options ||= {} seq_name = options[:name] || "#{self.name.downcase}_#{name}" before_create do send("#{name}=", @@incrementor.inc(seq_name, options, self)) end end