Module: Mongoid::Listable::Macros::ClassMethods
- Defined in:
- lib/mongoid/listable/macros.rb
Instance Method Summary collapse
-
#listed(options = {}) ⇒ Object
Macro to set basic position field on an object.
-
#lists(association, options = {}) ⇒ Mongoid:Relations:Metadata
Macro to set relation on which to make a list.
Instance Method Details
#listed(options = {}) ⇒ Object
Macro to set basic position field on an object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongoid/listable/macros.rb', line 18 def listed ={} config = { field: :position, scope: :list } config.merge! field config[:field], type: Integer created config[:field] updated config[:field] destroyed config[:field] scope config[:scope], order_by(config[:field] => :asc) self end |
#lists(association, options = {}) ⇒ Mongoid:Relations:Metadata
Macro to set relation on which to make a list
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mongoid/listable/macros.rb', line 45 def lists association, ={} = reflect_on_association association field_name = determine_position_field_name .klass.send :field, field_name, type: Integer ids_set association, set association, added association, removed association, .klass.send :include, Mongoid::Listable .klass.updated(field_name).destroyed(field_name) [:order] ||= "#{field_name} asc" end |