Module: Mongoid::Autoinc::ClassMethods
- Defined in:
- lib/autoinc.rb
Overview
Mongoid::Autoinc
class methods to allow for autoincrementing fields.
Instance Method Summary collapse
-
#incrementing_fields ⇒ Hash
Returns all incrementing fields of the document.
-
#increments(field, options = {}) ⇒ Object
Set an autoincrementing field for a
Mongoid::Document
.
Instance Method Details
#incrementing_fields ⇒ Hash
Returns all incrementing fields of the document
39 40 41 42 43 44 45 |
# File 'lib/autoinc.rb', line 39 def incrementing_fields if superclass.respond_to?(:incrementing_fields) @incrementing_fields ||= superclass.incrementing_fields.dup else @incrementing_fields ||= {} end end |
#increments(field, options = {}) ⇒ Object
Set an autoincrementing field for a Mongoid::Document
69 70 71 72 |
# File 'lib/autoinc.rb', line 69 def increments(field, = {}) incrementing_fields[field] = .reverse_merge!(auto: true) attr_protected(field) if respond_to?(:attr_protected) end |