Unleash.Plug (Unleash v5.1.2)

View Source

An extra fancy Plug and utility functions to help when developing Plug or Phoenix-based applications. It automatically puts together a Unleash.context/0 and stores it in the t:Plug.Conn.t()'s assigns.

To use, call plug Unleash.Plug in your plug pipeline. It depends on the session, and requires being after :fetch_session to work. It accepts the following options:

  • :user_id: The key under which the user's ID is found in the session.
  • :session_id: The key under wwhich the session ID is found in the session.

After which, enabled?/3 is usable.

Summary

Functions

Given a Plug.Conn.t/0, a feature, and (optionally) a boolean, return whether or not a feature is enabled. This requires this plug to be a part of the plug pipeline, as it will construct an Unleash.context()/0 out of the session.

Functions

enabled?(conn, feature, default \\ false)

@spec enabled?(Plug.Conn.t(), String.t() | atom(), boolean()) :: boolean()

Given a Plug.Conn.t/0, a feature, and (optionally) a boolean, return whether or not a feature is enabled. This requires this plug to be a part of the plug pipeline, as it will construct an Unleash.context()/0 out of the session.

Examples

iex> Unleash.Plug.enabled?(conn, :test)
false

iex> Unleash.Plug.enabled?(conn, :test, true)
true