It extend Active Record enums to OR values.
It has been implemented in bit operation.
Add this line to your application's Gemfile:
gem 'bitwise_enum', github: "osdakira/bitwise_enum"
And then execute:
bundle
Or install it yourself as:
gem install specific_install
gem specific_install -l 'git://github.com/osdakira/bitwise_enum.git'
class User < ActiveRecord::Base
bitwise_enum role: [ :admin, :worker ]
end
user.admin!
user.admin? # => true
user.role # => "['admin']"
user.admin!
user.admin? # => true
user.not_admin!
user.admin? # => false
user.role = :admin
user.admin? # => true
user.role # => ['admin']
user.admin! # => ['admin']
user.reset_role # => nil
user.role = []
User.admin # => SELECT `users`.* FROM `users` WHERE (role & 1 = 1)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request