Skip to content
This repository has been archived by the owner on Jan 4, 2018. It is now read-only.

asaaki/mongoid_bitfield

Repository files navigation

Mongoid::Bitfield

gem version build status

About

This tiny gem provides a bitfield or a collection of boolean bits/flags. This bitfield will be stored as an integer value in the MongoDB database.

Install

gem "mongoid_bitfield"

Usage

Model setup

class User
  include Mongoid::Document
  include Mongoid::Bitfield

  bitfield :flags, :is_admin, :adult, :drinker
end

Instance

without automatic saving

user = User.new
user.is_admin #=> false
user.is_admin = true
user.is_admin #=> true

atomic saving of changes

user = User.create!
user.drinker_enable!
user.reload
user.drinker #=> true

License

MIT/X11

2012—2014 Christoph Grabo