mongo_mapper_acts_as_list

This is a port of classic Rails’ acts_as_list to Mongo Mapper. This MongoMapper plugin provides the capabilities for sorting and reordering a number of objects in a list. If you do not specify custom position column in the options, a key named position will be added and used by default.

It has (almost) the same functionality and passes the original test-suite. Scope needs to be defined as symbol or array of symbols. It does not work for Embedded Documents.

Installation

Add this to your Gemfile and run the bundle command:

gem 'mongo_mapper_acts_as_list'

Example

class TodoList
  include MongoMapper::Document

  many :todo_items, :order => "position"
end

class TodoItem
  include MongoMapper::Document
  include MongoMapper::Plugins::ActsAsList

  key :todo_list_id, ObjectId
  belongs_to :todo_list

  acts_as_list :scope => :todo_list_id
end

todo_list.first.move_to_bottom
todo_list.last.move_higher

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Original Rails’ acts_as_list Copyright © 2007 David Heinemeier Hansson, released under the MIT license