public
Description: Simple bitmask attribute support for ActiveRecord
Homepage:
Clone URL: git://github.com/bruce/bitmask-attribute.git
bruce (author)
Mon May 18 18:59:50 -0700 2009
commit  a43c784e3eb5971a1d223621d8b17066f89ad6e5
tree    dd21c9118e1167dd51d69b029ffa73d13c772fce
parent  ed06af90b72afc40599a93e1aba5cded24a553ae
name age message
file .document Mon May 18 18:56:31 -0700 2009 Update documentation from old `bitmask_field` p... [bruce]
file .gitignore Mon May 18 18:30:23 -0700 2009 Initial commit to bitmask-attribute. [bruce]
file LICENSE Mon May 18 18:56:31 -0700 2009 Update documentation from old `bitmask_field` p... [bruce]
file README.markdown Mon May 18 18:56:31 -0700 2009 Update documentation from old `bitmask_field` p... [bruce]
file Rakefile Mon May 18 18:59:50 -0700 2009 Prepare for distribution [bruce]
file VERSION.yml Mon May 18 18:58:04 -0700 2009 Update version [bruce]
file bitmask-attribute.gemspec Mon May 18 18:59:50 -0700 2009 Prepare for distribution [bruce]
directory lib/ Loading commit data...
directory rails/ Mon May 18 18:56:31 -0700 2009 Update documentation from old `bitmask_field` p... [bruce]
directory test/
README.markdown

bitmask-attribute

Transparent manipulation of bitmask attributes.

Example

Simply declare an existing integer column as a bitmask with its possible values.

class User < ActiveRecord::Base
  bitmask :roles, :as => [:writer, :publisher, :editor] 
end

You can then modify the column using the declared values without resorting to manual bitmasks.

user = User.create(:name => "Bruce", :roles => [:publisher, :editor])
user.roles
# => [:publisher, :editor]
user.roles << :writer
user.roles
# => [:publisher, :editor, :writer]

For the moment, querying for bitmasks is left as an exercise to the reader, but here's how to grab the bitmask for a specific possible value for use in your SQL query:

bitmask = User.bitmasks[:roles][:editor]
# Use `bitmask` as needed

Modifying possible values

Once you have data using a bitmask, don't change the order of the values, remove any values, or insert any new values in the array anywhere except at the end.

Contributing and reporting issues

Please feel free to fork & contribute fixes via GitHub pull requests. The official repository for this project is http://github.com/bruce/bitmask-attribute

Issues can be reported at http://github.com/bruce/bitmask-attribute/issues

Copyright

Copyright (c) 2007-2009 Bruce Williams. See LICENSE for details.