Skip to content
/ enja Public

💂‍♂️👳‍♂️ Easy role definition. Supported by the enumerize gem for Rails.

License

Notifications You must be signed in to change notification settings

yhirano55/enja

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enja

Build Status Gem Version

Easy role definition. Supported by the enumerize gem for Rails.

Installation

gem 'enja'

Optionally, you can run the generator, which will set up a role field with some useful defaults for you:

$ bin/rails g enja:install

Usage

Call define_role_field in your resource of user model (User, AdminUser or Member etc):

class User < ApplicationRecord
  define_role_field :role, in: [:guest, :staff, :admin], default: :guest
end

Then it provides some convenient methods for implement role based system:

user = User.new(role: :guest)

# == Predicate Methods
user.guest? # true
user.staff? # false
user.admin? # false

# == Update Methods
user.guest! # => :guest
user.staff! # => :staff
user.admin! # => :admin

# == Scopes
User.guest.all # User.where(role: :guest).all
User.staff.all # User.where(role: :staff).all
User.admin.all # User.where(role: :admin).all

License

The gem is available as open source under the terms of the MIT License.

About

💂‍♂️👳‍♂️ Easy role definition. Supported by the enumerize gem for Rails.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published