Sha256: 065b407ccbc487b675cf70cee7ed9b4bfb6593673f0d2722ff57c6f1d13d0e51

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# What?

Mongoid::Orderable is a ordered list implementation for your mongoid models.

# Why?

* It uses native mongo batch increment feature
* It supports assignable api
* It proper assingns position while moving document between scopes

# How?

```
gem 'mongoid_orderable'
```

Gem has the same api as others. Just include Mongoid::Orderable into your model.
Also you can initialize orderable manually and specify `:scope` or `:column` options:

```
class Item
  include Mongoid::Document
  include Mongoid::Orderable

  # belongs_to :group

  # orderable :scope => :group, :column => :pos
  # orderable :scope => lambda { |document| where(:group_id => document.group_id) }
end
```

# Usage

```
item.move_to 2 # just change position
item.move_to! 2 # and save
item.move_to = 2 # assignable method

# symbol position
item.move_to :top
item.move_to :bottom
item.move_to :higher
item.move_to :lower

# generated methods
item.move_to_top
item.move_to_bottom
item.move_higher
item.move_lower
```

# Contributing

Fork && Patch && Spec && Push && Pull request.

# License

Mongoid::Orderable is released under the MIT license.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid_orderable-0.9.1 README.md
mongoid_orderable-0.9.0 README.md