Flippant.Rules behaviour (Flippant v2.0.0) View Source
The Rules module glues rules, actors, and groups are together.
Link to this section Summary
Functions
Check whether any rules are enabled for a particular actor. The function accepts a list of names/value pairs and an actor.
Callbacks
Validate that an actor is both a member of group and in the enabled_for list. For example,
if we had a staff group, and a rule containing %{"staff" => ids}, we could have a function
like this
Link to this section Types
Specs
actor() :: term()
Specs
rules() :: Enumerable.t()
Link to this section Functions
Specs
Check whether any rules are enabled for a particular actor. The function accepts a list of names/value pairs and an actor.
Link to this section Callbacks
Specs
Validate that an actor is both a member of group and in the enabled_for list. For example,
if we had a staff group, and a rule containing %{"staff" => ids}, we could have a function
like this:
def enabled?("staff", enabled_for, %{staff: true} = actor) do
Enum.any?(enabled_for, &actor.id == &1.id)
endThis both validates the actor is staff, and that the actor is in the enabled list. Allowing rules definition in this way makes the logic for rule checking very visible in application code.