DevJoy.API.Storage behaviour (DevJoy v2.0.0)
View SourceThe Storage API defines a set of storage callbacks to implement
as well as functions that call a callback implementation for the configured storage module.
The default storage module that implements this module's behaviour is DevJoy.Session.Storage.
Usage
The storage can be configured:
- globally using the
:session_storageconfiguration keyconfig :dev_joy, :session_storage, MyApp.Storage - per process using set_storage/1 function
DevJoy.API.Storage.set_storage(MyApp.Storage)
Summary
Types
The type representing a session's history.
The type representing the session's history entry.
The type representing the session's history index (0-based).
The type representing the session's locale.
Functions
Sets a storage implementation to be used within current process.
Types
@type history() :: [history_entry()]
The type representing a session's history.
The history is simply a list of the history entries.
@type history_entry() :: {DevJoy.Scene.t(), DevJoy.Scene.Part.name(), DevJoy.API.Item.index(), max_index :: DevJoy.API.Item.index()}
The type representing the session's history entry.
The entry is 4-element tuple containing:
The 'max_index' value is used to determine whether or not it's possible to navigate forward in the history.
@type history_index() :: non_neg_integer()
The type representing the session's history index (0-based).
@type locale() :: String.t()
The type representing the session's locale.
Callbacks
@callback get_history() :: history()
Gets a history/0
Usage
history = DevJoy.API.Storage.get_history()
is_list(history)
# => true@callback get_history_index() :: history_index()
Gets a history_index/0
Usage
index = DevJoy.API.Storage.get_history_index()
is_integer(index) and index >= 0
# => true@callback get_locale() :: locale()
Gets a locale/0
Usage
locale = DevJoy.API.Storage.get_locale()
is_binary(locale)
# => true@callback set_history(history()) :: :ok
Sets a history/0
Usage
:ok = DevJoy.API.Storage.set_history([])
history = DevJoy.API.Storage.get_history()
history == []
# => true@callback set_history_index(history_index()) :: :ok
Sets a history_index/0
Usage
:ok = DevJoy.API.Storage.set_history_index(0)
index = DevJoy.API.Storage.get_history_index()
index == 0
# => true@callback set_locale(locale()) :: :ok
Sets a locale/0
Usage
:ok = DevJoy.API.Storage.set_locale("en")
locale = DevJoy.API.Storage.get_locale()
locale == "en"
# => trueFunctions
@spec set_storage(module()) :: :ok
Sets a storage implementation to be used within current process.