Skip to content

rspine/permissions

Repository files navigation

Spine::Permissions

Gem Version Dependency Status Test Coverage Code Climate security Inline docs Codeship Status for rspine/permissions

Installation

To install it, add the gem to your Gemfile:

gem 'spine-permissions'

Then run bundle. If you're not using Bundler, just gem install spine-permissions.

Usage

Global permissions

permissions = Spine::Permissions::Collection.new
permissions.grant(:all, :all)
  .deny(:all, :projects)
  .deny(:write, :tasks)

permissions.granted?(:read, :projects)
# => false
permissions.denied?(:write, :tasks)
# => true

Role based permissions

roles = Spine::Permissions::Roles.new
roles.define(:user)
  .grant(:all, :all)
  .deny(:all, :projects)
  .deny(:write, :tasks)

roles.define(:admin)
  .grant(:all, :all)

roles.granted?(:user, :read, :tasks)
# => true
roles.denied?(:admin, :write, :tasks)
# => false