0.0
No commit activity in last 3 years
No release in over 3 years
Simple list behavior for Mongoid
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.8.0
>= 4.2.0
>= 2.0.0
>= 2.8.0
>= 3.1.0

Runtime

~> 4.0.0
 Project Readme

Mongoid List

Mongoid List uses a position column to maintain an ordered list, with optional scoping. It uses atomic updates to keep lists in either a Collection or Embedded in sync.

Starting with version 0.7.0, Mongoid 5+ is required. If you want Mongoid 4 support use the 0.6.0 version of this gem.

Installation

Add to your Gemfile:

gem 'mongoid-list'

Usage

Add a list:

class CrowTRobot
  include Mongoid::Document
  include Mongoid::List

  lists

end

Available methods:

# Update Position

doc1.position  # => 1
doc2.position  # => 2

doc1.position = 2
doc1.save

doc1.position  # => 2
doc2.position  # => 1


# Reorder a Full List
Klass.update_positions_in_list!(elements)

Pass in all elements in new ordering.  Accepts documents or ids.

# Scope Information
doc.list_scoped?  		# If scoping has been defined
doc.list_scope_field		# Which field to scope against
doc.list_scope_value		# Value of the scoping field
doc.list_scope_conditions	# Additional query conditions for scoped lists.

Scoping

To scope the list, pass :scope on lists definition:

class TomServo
  include Mongoid::Document
  include Mongoid::List

  lists scope: :satellite_of_love_id
  belongs_to :satellite_of_love

end

TO-DO

  • Helper methods to move individual documents within the list.
  • Customizable filed name.