Git Product home page Git Product logo

mongoid_orderable's Introduction

Build Status

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
  • It supports both mongoid 2 and 3

How?

gem 'mongoid_orderable'

Gem has the same api as others. Just include Mongoid::Orderable into your model and call orderable method.

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

  # belongs_to :group

  # orderable
  # orderable :scope => :group, :column => :pos
  # orderable :scope => lambda { |document| where(:group_id => document.group_id) }
  # orderable :index => false # this one if you want specify indexes manually
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.

mongoid_orderable's People

Contributors

pyromaniac avatar semaperepelitsa avatar mattiassvedhem avatar

Watchers

François KLINGLER avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.