Mediate.Rbac.Binding (mediate_rbac v0.1.0)

Copy Markdown View Source

What Mediate.Rbac needs beyond the configuration: the policy module and the mediated repo its rules read through. bind/1 validates the pair and keeps it for the life of the VM, as Mediate.Config.boot!/1 keeps the configuration. override/1 puts a binding in the current process for the rest of its life. resolve/0 reads it from the caller and from its $callers chain. So a test binds its own policy and repo and leaves the boot binding alone.

Summary

Types

t()

The bound pair: the policy module, and the repo its rules read through.

Functions

Validates once at boot and keeps the binding for resolve/0.

bind/1, but raises the error.

Validates the pair into the struct.

The schema of the binding's options.

Overrides the binding's fields for the rest of the current process.

Overrides the binding's fields around a function. Puts the previous override back after it.

The boot binding under the current process's overrides, or an error when neither exists.

The binding as the keyword list new/1 accepts.

Types

t()

@type t() :: %Mediate.Rbac.Binding{policy: module(), repo: module()}

The bound pair: the policy module, and the repo its rules read through.

Functions

bind(options)

@spec bind(keyword()) :: {:ok, t()} | {:error, Mediate.Error.t()}

Validates once at boot and keeps the binding for resolve/0.

bind!(options)

@spec bind!(keyword()) :: t()

bind/1, but raises the error.

new(options)

@spec new(keyword()) :: {:ok, t()} | {:error, Mediate.Error.t()}

Validates the pair into the struct.

options_schema()

@spec options_schema() :: NimbleOptions.t()

The schema of the binding's options.

override(overrides)

@spec override(keyword()) :: :ok

Overrides the binding's fields for the rest of the current process.

override(overrides, fun)

@spec override(keyword(), (-> result)) :: result when result: term()

Overrides the binding's fields around a function. Puts the previous override back after it.

resolve()

@spec resolve() :: {:ok, t()} | {:error, Mediate.Error.t()}

The boot binding under the current process's overrides, or an error when neither exists.

to_keyword(binding)

@spec to_keyword(t()) :: keyword()

The binding as the keyword list new/1 accepts.