Module: MongoMapper::Plugins::SortableItem::ClassMethods
- Defined in:
- lib/mm_sortable_item.rb
Instance Method Summary collapse
- #conditions_for_list_scope(list_id) ⇒ Object
- #in_list(list_id = nil) ⇒ Object
- #list_scope_column ⇒ Object
- #list_scope_column=(new_column) ⇒ Object
- #reorder(ids) ⇒ Object
Instance Method Details
#conditions_for_list_scope(list_id) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/mm_sortable_item.rb', line 33 def conditions_for_list_scope list_id the_query = {} the_column = list_scope_column if the_column the_query = { the_column => list_id } end the_query end |
#in_list(list_id = nil) ⇒ Object
29 30 31 |
# File 'lib/mm_sortable_item.rb', line 29 def in_list list_id = nil where(conditions_for_list_scope(list_id)) end |
#list_scope_column ⇒ Object
46 47 48 |
# File 'lib/mm_sortable_item.rb', line 46 def list_scope_column self.[:list_scope] end |
#list_scope_column=(new_column) ⇒ Object
42 43 44 |
# File 'lib/mm_sortable_item.rb', line 42 def list_scope_column= new_column self.[:list_scope] = new_column end |
#reorder(ids) ⇒ Object
23 24 25 26 27 |
# File 'lib/mm_sortable_item.rb', line 23 def reorder(ids) ids.each_with_index do |id, index| set(id, :position => index + 1) end end |