View Source NavEx (NavEx v0.1.0)

NavEx is a navigation history tool that uses adapter pattern and lets you choose between available adapters or just to write your own adapter.

There are 2 available adapters right now - ETS adapter storing user navigation history in the ETS and Session adapter storing user navigation history in user's sessions.

## Configuration:

  config :nav_ex,
  tracked_methods: ["GET"], # what methods to track
  history_length: 10, # what is the history list length per user
  adapter: NavEx.Adapters.ETS # adapter used by NavEx to save data

### ETS Adapter config

config NavEx.Adapters.ETS,
  identity_key: "nav_ex_identity", # name of the key in cookies where the user's identity is saved
  table_name: :navigation_history # name of the ETS table

## Session Adapter config

config NavEx.Adapters.Session,
  history_key: "nav_ex_history" # name of the key in session where navigation history is saved

Link to this section Summary

Functions

Used by ExNav.Plug. Takes %Plug.Conn{} as an input.

Takes %Plug.Conn{} as an input. Calls Adapter last_path/1 function.

Takes %Plug.Conn{} as an input. Calls Adapter list/1 function.

Takes %Plug.Conn{} and number as inputs. Calls Adapter path_at/1 function.

Link to this section Functions

Used by ExNav.Plug. Takes %Plug.Conn{} as an input.

Calls Adapter insert/1 function. Always returns {:ok, %Plug.Conn{}} tuple.

## Examples

iex(1)> NavEx.insert(conn)
{:ok, %Plug.Conn{...}}

Takes %Plug.Conn{} as an input. Calls Adapter last_path/1 function.

## Examples

# for existing user
iex(1)> NavEx.last_path(conn)
{:ok, "/sample/path"}

# for existing user, but without 2 paths
iex(2)> NavEx.last_path(conn)
{:ok, nil}

# for not existing user
iex(3)> NavEx.last_path(conn)
{:error, :not_found}

Takes %Plug.Conn{} as an input. Calls Adapter list/1 function.

## Examples

# for existing user
iex(1)> NavEx.list(conn)
{:ok, ["/sample/path/2", "sample/path/1]}

# for not existing user
iex(2)> NavEx.list(conn)
{:error, :not_found}

Takes %Plug.Conn{} and number as inputs. Calls Adapter path_at/1 function.

## Examples

# for existing user
iex(1)> NavEx.path_at(conn, 5)
{:ok, "/sample/path"}

# for existing user but exceeding paths number
iex(2)> NavEx.path_at(conn, 5)
{:ok, nil}

# for not existing user
iex(3)> NavEx.path_at(conn, 5)
{:error, :not_found}

# exceeding history limit
iex(4)> NavEx.path_at(conn, 999)
** (ArgumentError) Max history depth is 10 counted from 0 to 9. You asked for record number 999.