Home > attribute_bitmask

attribute_bitmask

Attribute_bitmask is a project mainly written in Ruby, based on the MIT license.

Treat an attribute as a bitmask

AttributeBitmask

Attribute Bitmask is designed to allow you to create accessor methods to access bitmask fields as if they were boolean attributes in the model.

Example

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

class User < ActiveRecord::Base bitmask :roles, :writer, :publisher, :editor, :proofreader end

You can then access the bitmask fields as if they were boolean columns.

user = User.create(:name => "Bruce", :publisher => true, :editor => true) user.publisher?

=> true

user.writer?

=> false

user.writer = true user.writer

=> true

user.writer?

=> true

user.roles

=> 7

Copyright (c) 2010 [Robert Ferney], released under the MIT license