Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A tiny MongoMapper plugin to provide some basic list functionality.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 mm_sortable_item.gemspec
README.md

mm_sortable_item

This is a quick little MongoMapper plugin that provides some basic acts-as-list style functionality on mongo documents. By default things are added to the list bottom.

Usage

In the gemfile:

gem 'mm_sortable_item'

In your model:

  class SortableDocument
    include MongoMapper::Document
    plugin MongoMapper::Plugins::SortableItem

    list_scope_column :parent_id # optional if you want to scope the lists

    # ...
  end

Then you have access to some helpful methods, such as:

  • .in_order retrieves the list items in order
  • .in_list(id) retrieves the items scoped as you wish
  • .reorder(orderd_array_of_ids) sets the positions of the given ids in order
  • object.set_position(position) inserts object into the list at the given position

Credit

John Nunemaker for mongo_mapper itself, as well as a start down the road of how to implement this. It's definitely not as "fully functional" as acts_as_list, but it does everything I need :).

Something went wrong with that request. Please try again.