Skip to content

wizardone/can_i

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published

Languages