0.0
No commit activity in last 3 years
No release in over 3 years
Permissions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Permissions

A small library for adding permissions to an application for authorization.

Installation

gem install permissions

Usage

API

for(*keys, &block): Creates a permission with the given block for each key.

authorize?(key, *args): Runs permission block for key with args.

deep_dup: Copies permissions to a new object.

Authorizable

permissions: Must be implemented by your application.

authorize_for?(key, *args) Based off the implemented permissions, calls block with self and args for the given key.

Example

require 'permissions'

class User
  include Permissions::Authorizable

  def initialize(permissions)
    @permissions = permissions
  end
end

class Command
  attr_reader :user

  def initialize(user)
    @user = user
  end
end

permissions = Permissions.new

permissions.for(Command) { |user, command| user == command.user }

user = User.new(permissions)

foo = Command.new(user)

bar = Command.new(nil)

user.authorize_for?(Command, foo) # true

user.authorize_for?(Command, bar) # false

permissions.authorize?(Command, user, foo) # true

permissions.authorize?(Command, user, bar) # false