Giter Site home page Giter Site logo

rollable's Introduction

Rollable

Rollable is a Rails gem that adds agnostic roles to your application. The core principle is that a role should not
be coupled to any object, but is nothing more than a relationship. Rollable does not define semantics, you can use
cancan or some similar gem to do just that.

Installation

Add to your gemfile

gem ‘rollable’

And run

bundle install

Setup

Rollable is ment to be easy and maintainable, with a minimal amount of configuration nescecary.

Setup the role model and migration, where is the model name you want to be able to have roles

rails generate rollable:setup
rake db:migrate

Configuration

Just two lines!

In the model you defined during setup:

include Rollable::Base
rollables model names, option hash

Currently, the available options are:

:roles => [Array of Strings] # Role names
:allow_nil => false # If true, you can create generic roles (like ‘admin’)

Features

  • Hardly any configuration
  • Validates role names, role types by inclusion and user presence on Role (all dynamic)
  • Much more!

Usage

We’ll call the model that can have roles users, for the sake of laziness.

Rollable provides helpers based on role names to check whether a user has a role on an object:

user.is_owner_of?(horse) # => true

You can also request all possible roles

User.role_names

You can set roles easily by using the helper

user.is_owner(horse)

If you use nil roles, you can also do

user.is_admin?

Since 0.0.2 you can also do

target_model.has_admin?

And, to get all users with that role

target_model.get_admins

Limitations

  • Its the first release, don’t whine.
  • Role names can only be single words (so no underscores), but keep it simple, right?

Questions? Comments? Contribute? All welcome!

- Timon Vonk

rollable's People

Contributors

timonv avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.