Z.Preferences (Portico/Z v0.1.0)
Context module for getting + setting entries from a ZSchemas.Preference
Preferences are key/value information that's stored relative to a module name. There's no defined structure for most preferences, because each module will have different needs for the shape of that data. Nothing's keeping us from defining schemas for preference data, however, and this is encouraged for larger and more mission-critical modules so that we can do pre-validation etc.
Link to this section Summary
Functions
Retrieve all preferences for a ZSchemas.Account/ module combination
Retrieve a preference value for a given ZSchemas.Account, module, and key
Set a preference or series of preferences for a ZSchemas.Account in a module.
Link to this section Functions
get(account, module)
Retrieve all preferences for a ZSchemas.Account/ module combination
Will return %{} if no preferences are found.
get(account, module, key, default \\ nil)
Retrieve a preference value for a given ZSchemas.Account, module, and key
Note that String and Atom key values will be treated equivalently. All atom keys are converted to strings in the database.
You can set a default which will be used if no preference is found. The standard default is nil.
Examples
Z.Preferences.get(account, __MODULE__, :cheese)
"brie"
Z.Preferences.get(account, __MODULE__, :does_not_exist, 123)
123
set(account, module, args \\ [])
Set a preference or series of preferences for a ZSchemas.Account in a module.
Examples
Z.Preferences.set(account, __MODULE__, debug: true, cheese: "brie")
%ZSchemas.Preference{preferences: %{"debug" => true, "cheese" => "brie"}}