Sha256: f88ae83e2be51ea586c4164c8c93fc5965aa63082cf01154e83534e22ddafedb
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
# ActiveRecordBitmask Transparent manipulation of bitmask attributes for ActiveRecord ## Installation Add this line to your application's Gemfile: ```ruby gem 'active_record_bitmask' ``` And then execute: $ bundle Or install it yourself as: $ gem install active_record_bitmask ## Usage Simply declare an existing integer column as a bitmask. ```ruby class Post < ApplicationRecord bitmask(roles: [:administrator, :provider, :guest]) end ``` You can then modify the column using the declared values. ```ruby post = Post.create(roles: [:provider, :guest]) post.roles #=> [:provider, :guest] post.roles += [:administrator] post.roles #=> [:administrator, :provider, :guest] ``` You can check bitmask ```ruby post = Post.create(roles: [:provider, :guest]) post.roles?(:provider) #=> false post.roles?(:guest, :provider) #=> true ``` You can get the definition of bitmask ```ruby map = Post.bitmask_for(:rules) map.keys #=> [:administrator, :provider, :guest] map.values #=> [1, 2, 4] ``` ### Scopes #### `with_roles` #### `with_any_roles` #### `without_roles` #### `with_exact_roles` #### `no_roles` ## Development After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake` to run the tests. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/alpaca-tc/active_record_bitmask.
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_record_bitmask-0.0.3 | README.md |
active_record_bitmask-0.0.2 | README.md |