Sha256: 956692c35639b0aa424225b6edf4d9f9caeb7a53c81608d76abc4b8ff38b66e7

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# Bitroleable

Store user's roles in an integer column of database. Have ability to store multi-roles for users.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'bitroleable'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install bitroleable

## Usage

Add a column which will store role/roles as integer:

```ruby
add_column :user, :role, :integer, null: false
```

And then tell a model that you use this gem functionality:

```ruby
# app/models/user.rb
class User < ActiveRecord::Base
  roleable :role, [:user, :moderator, :admin], multi: true
end
```

So you can do this:

```ruby
user = User.first
user.admin!
user.admin? # => true
user.user? # => false
user.role # => [:admin]
user.role = [:user, :moderator]
user.role # => [:user, :moderator]
user.save!

User.where_role(:admin).count # => 0
User.where_role(:user).count # => 1
User.where_role(:moderator).count # => 1
```

## Contributing

1. Fork it ( https://github.com/ekondr/bitroleable/fork )
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 a new Pull Request

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bitroleable-0.0.2 README.md
bitroleable-0.0.1 README.md