Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 1.22 KB

README.md

File metadata and controls

46 lines (36 loc) · 1.22 KB

CanI

Build Status

Simple authorization system for Elixir based applications.

Define your abilities like so:

# 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, the package can be installed by adding can_i to your list of dependencies in mix.exs:

def deps do
  [
    {:can_i, "~> 0.1.1"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/can_i.