Sha256: 38ef724a0e60a67fb1e38ab23fe6036f36ce3783eec5936f3eaaa50e7742a579

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# 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.

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
bruce-bitmask-attribute-1.0.0 README.markdown
bitmask-attribute-1.0.0 README.markdown