Skip to content

mugenup/bitwise_enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BitwiseEnum

It extend Active Record enums to OR values. It has been implemented in bit operation.

Installation

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'

Usage

  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)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages