Module: Mongoid::Listable::Macros::ClassMethods
- Defined in:
- lib/mongoid/listable/macros.rb
Instance Method Summary collapse
-
#listed ⇒ Object
Macro to set basic position field on an object.
-
#lists(name, options = {}) ⇒ Mongoid:Relations:Metadata
Macro to set relation on which to make a list.
Instance Method Details
#listed ⇒ Object
Macro to set basic position field on an object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mongoid/listable/macros.rb', line 18 def listed field :position, type: Integer created(:position) .updated(:position) .destroyed(:position) scope :list, order_by(:position => :asc) self end |
#lists(name, options = {}) ⇒ Mongoid:Relations:Metadata
Macro to set relation on which to make a list
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mongoid/listable/macros.rb', line 37 def lists name, ={} = reflect_on_association name field_name = field_name() .klass.send :field, field_name, type: Integer ids_set(name, ).set(name, ) .added(name, ).removed(name, ) .klass.send :include, Mongoid::Listable .klass.updated(field_name).destroyed(field_name) [:order] ||= "#{field_name(meta)} asc" end |