Sha256: 61f00face81f96d16e82bbdda66e298c56162869e807a8699303be2a93f15d06

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

# Enja

[![Build Status](https://travis-ci.org/yhirano55/enja.svg?branch=master)](https://travis-ci.org/yhirano55/enja)
[![Gem Version](https://badge.fury.io/rb/enja.svg)](https://badge.fury.io/rb/enja)

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

## Installation

```ruby
gem 'enja'
```

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

```bash
$ bin/rails g enja:install
```

## Usage

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

```ruby
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:

```ruby
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](http://opensource.org/licenses/MIT).

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
enja-0.1.2 README.md
enja-0.1.1 README.md