🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

bitroleable

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitroleable

0.0.4
Rubygems
Version published
Maintainers
1
Created
Source

Bitroleable

Manage user roles. Each user's role is stored as a bit in an integer column of database. Also provides user ability to have one role and some roles.

Installation

Add this line to your application's Gemfile:

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:

add_column :user, :roles, :integer, null: false

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

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

Options

For now it has only one option:

  • multi (boolean) - when it equals true an entity could have many roles, otherwise only one role

Example

user = User.first
user.admin! # => user becomes an admin
user.admin? # => true
user.role?(: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
User.roles_list # => [:user, :moderator, :admin]
User.role?(:user) # => true
User.role?(:fake) # => false

Contributing

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

FAQs

Package last updated on 26 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts