https://github.com/wizardone/can_i
Authorization system for Elixir
https://github.com/wizardone/can_i
authorization elixir simple system
Last synced: 25 days ago
JSON representation
Authorization system for Elixir
- Host: GitHub
- URL: https://github.com/wizardone/can_i
- Owner: wizardone
- Created: 2018-01-29T12:48:59.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-26T10:30:11.000Z (over 8 years ago)
- Last Synced: 2026-02-22T05:51:25.668Z (4 months ago)
- Topics: authorization, elixir, simple, system
- Language: Elixir
- Size: 11.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CanI
[](https://travis-ci.org/wizardone/can_i)
Simple authorization system for Elixir based applications.
Define your abilities like so:
```elixir
# Start the agent
CanI.start_link
# Add abilities
CanI.register(:read, fn user -> user.regular? end)
CanI.register(:delete, fn user -> user.admin? end)
# Add multiple abilities
CanI.register([:insert, :delete], fn user -> user.admin? end)
CanI.abilities
#=> [{:read, function}, {:delete, function}]
# Fetch a user record from a database that is supposed to be able to
# delete records
CanI.check_ability(:delete, user)
=> true
# Or if there are no arguments involved for the anonymous function
CanI.register(:read, fn -> false end)
CanI.check_abilities(:read)
=> false
```
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `can_i` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:can_i, "~> 0.1.1"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/can_i](https://hexdocs.pm/can_i).