DevJoy.API.Storage behaviour (DevJoy v2.0.0)

View Source

The 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_storage configuration key
    config :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

history()

@type history() :: [history_entry()]

The type representing a session's history.

The history is simply a list of the history entries.

history_entry()

@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:

  1. scene name
  2. part name
  3. item index
  4. max index

The 'max_index' value is used to determine whether or not it's possible to navigate forward in the history.

history_index()

@type history_index() :: non_neg_integer()

The type representing the session's history index (0-based).

locale()

@type locale() :: String.t()

The type representing the session's locale.

Callbacks

get_history()

@callback get_history() :: history()

Gets a history/0

Usage

history = DevJoy.API.Storage.get_history()
is_list(history)
# => true

get_history_index()

@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

get_locale()

@callback get_locale() :: locale()

Gets a locale/0

Usage

locale = DevJoy.API.Storage.get_locale()
is_binary(locale)
# => true

set_history(history)

@callback set_history(history()) :: :ok

Sets a history/0

Usage

:ok = DevJoy.API.Storage.set_history([])
history = DevJoy.API.Storage.get_history()
history == []
# => true

set_history_index(history_index)

@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

set_locale(locale)

@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"
# => true

Functions

set_storage(module)

@spec set_storage(module()) :: :ok

Sets a storage implementation to be used within current process.