Flippant v0.4.1 Flippant.Registry View Source

The registry stores group names with corresponding inclusion functions.

Groups are used to identify and qualify actors. Typically an actor is a “user”, but it could be a company, a device, or any other entity that needs to be classified.

Using the example of a User some groups may be “nobody”, “everbody”, “admin”, “staff”, etc. Each named group is coupled with a function that accepts two arguments (the actor and optional values) and returns a boolean. When the return value is true, the actor belongs to that group. If the value is false then they aren’t part of the group.

Examples

Flippant.register("nobody", fn(_, _) -> false end)
#=> :ok

Flippant.register("everybody", fn(_, _) -> true end)
#=> :ok

Group registry is stateful, and global to a Flippant instance. That means an actor can be evaulated against every group for every feature check. Be sure to add guards if you are mixing different types of actors.

Flippant.register("enterprise", fn
  nil, _values -> false
  %User{}, _values -> false
  %Company{id: id}, values -> id in values
end)
#=> :ok

Link to this section Summary

Functions

Start the registry process

Link to this section Functions

Start the registry process.