Module: MongoidAutoInc::ClassMethods
- Defined in:
- lib/mongoid_auto_inc.rb
Instance Method Summary collapse
Instance Method Details
#auto_increment(name, options = {}) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/mongoid_auto_inc.rb', line 7 def auto_increment(name, ={}) field name, :type => Integer seq_name = "#{self.name.downcase}_#{name}" incrementor = MongoidAutoInc::Incrementor.new() before_create { self.send("#{name}=", incrementor[seq_name].inc) unless self[name.to_sym].present? } end |