MongoidToggle Build Status Code Climate

MongoidToggle adds a simple function to mongoid documents to toggle boolean values with optional save for the record.

Install

 gem 'mongoid_toggle'

Usage

 class Person
   include Mongoid::Document
   include Mongoid::Toggle

   field :name, :type => String
   field :is_active, :type => Boolean
 end
 p = Person.first

 # This call toggles is_active and saves the record and returns true on success
 p.toggle! :is_active

 # This call toggles is_active without saving the record and always returns true
 p.toggle :is_active

Credits

Copyright (c) 2012-2013 Thomas Boerger Programmierung http://www.tbpro.de