BitmaskAttributesHelpers
Quick and simple helpers for Joel Moss’ bitmask_attributes gem. These helpers include frequently used checkers, setters, getters, and scopes pertaining to the bitmasks.
## Installation ##
The best way to install is with RubyGems:
$ [sudo] gem install bitmask_attributes_helpers
Or better still, just add it to your Gemfile:
gem 'bitmask_attributes_helpers'
## Examples/Usage ##
There are four class methods we use to install the requisite helpers: ‘bitmask_presence_methods`, `bitmask_scopes`, `bitmask_virtual_attributes`, and `bitmask_helpers`. Each takes the name of the bitmask as an argument.
“‘Ruby
class Model < ActiveRecord::Base
bitmask :colors, as: [:red, :blue, :green]
bitmask_presence_methods :colors
# Enables value checkers, i.e.
# model.red? => true if model has the red bitmask attribute set
bitmask_scopes :colors
# Enables scopes to search Model by bitmask values, i.e.
# Model.red => all models which have the red bit set to true
# Model.not_red => all models which have the red bit set to false
bitmask_virtual_attributes :colors
# Creates a virtual attribute on the model for each value of the bitmask,
i.e.
# model.red = true => sets the red bitmask to true
# model.red => true, as we've sets the bitmask to true
bitmask_helpers :colors
# This is a macro to enable all of the above for a specific bitmask
...
“‘
Contributing
-
Fork it.
-
Create a branch (‘git checkout -b new-feature`)
-
Make your changes
-
Run the tests (‘bundle install` then `bundle exec rake`)
-
Commit your changes (‘git commit -am “Created new feature”`)
-
Push to the branch (‘git push origin new-feature`)
-
Create a pull request from your branch.
-
Promote it. Get others to drop in and +1 it.
Credits
Joel Moss deserves all the credit for his wonderful bitmask_attributes gem
Copyright
Copyright © 2013 Ryan Chan