Project

enja

0.0
No commit activity in last 3 years
No release in over 3 years
Easy role definition. Supported by the enumerize gem for Rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15

Runtime

 Project Readme

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.