NavEx.Adapter behaviour (NavEx v0.1.6)

View Source

Behaviour of the NavEx adapter saving the navigation history data.

Summary

Callbacks

Lists children of the adapter to be started with the application. For example ETS table if your adapter needs it.

Inserts the path into user's navigation history. Takes %Plug.Conn{} as an argument, based on that fetches or creates user's identity (for example as an ID in session) and saves his path into the storage.

Returns user's last path. In case if user is not found or has no last path returns error tuple.

Lists user navigation history. In case if user is not found returns {:error, :not_found} tuple.

Returns user's Nth last path. In case if user is not found returns an error tuple. In case if number exceeds the navigation history limit returns an error tuple. In case if number exceed the user's navigation history records number returns an error tuple.

Callbacks

children()

@callback children() :: list()

Lists children of the adapter to be started with the application. For example ETS table if your adapter needs it.

insert(%Plug.Conn{})

@callback insert(%Plug.Conn{
  adapter: term(),
  assigns: term(),
  body_params: term(),
  cookies: term(),
  halted: term(),
  host: term(),
  method: term(),
  owner: term(),
  params: term(),
  path_info: term(),
  path_params: term(),
  port: term(),
  private: term(),
  query_params: term(),
  query_string: term(),
  remote_ip: term(),
  req_cookies: term(),
  req_headers: term(),
  request_path: term(),
  resp_body: term(),
  resp_cookies: term(),
  resp_headers: term(),
  scheme: term(),
  script_name: term(),
  secret_key_base: term(),
  state: term(),
  status: term()
}) ::
  {:ok,
   %Plug.Conn{
     adapter: term(),
     assigns: term(),
     body_params: term(),
     cookies: term(),
     halted: term(),
     host: term(),
     method: term(),
     owner: term(),
     params: term(),
     path_info: term(),
     path_params: term(),
     port: term(),
     private: term(),
     query_params: term(),
     query_string: term(),
     remote_ip: term(),
     req_cookies: term(),
     req_headers: term(),
     request_path: term(),
     resp_body: term(),
     resp_cookies: term(),
     resp_headers: term(),
     scheme: term(),
     script_name: term(),
     secret_key_base: term(),
     state: term(),
     status: term()
   }}

Inserts the path into user's navigation history. Takes %Plug.Conn{} as an argument, based on that fetches or creates user's identity (for example as an ID in session) and saves his path into the storage.

insert(%Phoenix.LiveView.Socket{}, t)

@callback insert(
  %Phoenix.LiveView.Socket{
    assigns: term(),
    endpoint: term(),
    fingerprints: term(),
    host_uri: term(),
    id: term(),
    parent_pid: term(),
    private: term(),
    redirected: term(),
    root_pid: term(),
    router: term(),
    sticky?: term(),
    transport_pid: term(),
    view: term()
  },
  String.t()
) ::
  {:ok,
   %Phoenix.LiveView.Socket{
     assigns: term(),
     endpoint: term(),
     fingerprints: term(),
     host_uri: term(),
     id: term(),
     parent_pid: term(),
     private: term(),
     redirected: term(),
     root_pid: term(),
     router: term(),
     sticky?: term(),
     transport_pid: term(),
     view: term()
   }}

last_path(%Plug.Conn{})

@callback last_path(%Plug.Conn{
  adapter: term(),
  assigns: term(),
  body_params: term(),
  cookies: term(),
  halted: term(),
  host: term(),
  method: term(),
  owner: term(),
  params: term(),
  path_info: term(),
  path_params: term(),
  port: term(),
  private: term(),
  query_params: term(),
  query_string: term(),
  remote_ip: term(),
  req_cookies: term(),
  req_headers: term(),
  request_path: term(),
  resp_body: term(),
  resp_cookies: term(),
  resp_headers: term(),
  scheme: term(),
  script_name: term(),
  secret_key_base: term(),
  state: term(),
  status: term()
}) :: {:ok, String.t()} | {:error, atom()}
@callback last_path(%Phoenix.LiveView.Socket{
  assigns: term(),
  endpoint: term(),
  fingerprints: term(),
  host_uri: term(),
  id: term(),
  parent_pid: term(),
  private: term(),
  redirected: term(),
  root_pid: term(),
  router: term(),
  sticky?: term(),
  transport_pid: term(),
  view: term()
}) :: {:ok, String.t()} | {:error, atom()}

Returns user's last path. In case if user is not found or has no last path returns error tuple.

list(%Plug.Conn{})

@callback list(%Plug.Conn{
  adapter: term(),
  assigns: term(),
  body_params: term(),
  cookies: term(),
  halted: term(),
  host: term(),
  method: term(),
  owner: term(),
  params: term(),
  path_info: term(),
  path_params: term(),
  port: term(),
  private: term(),
  query_params: term(),
  query_string: term(),
  remote_ip: term(),
  req_cookies: term(),
  req_headers: term(),
  request_path: term(),
  resp_body: term(),
  resp_cookies: term(),
  resp_headers: term(),
  scheme: term(),
  script_name: term(),
  secret_key_base: term(),
  state: term(),
  status: term()
}) :: {:ok, list()} | {:error, :not_found}
@callback list(%Phoenix.LiveView.Socket{
  assigns: term(),
  endpoint: term(),
  fingerprints: term(),
  host_uri: term(),
  id: term(),
  parent_pid: term(),
  private: term(),
  redirected: term(),
  root_pid: term(),
  router: term(),
  sticky?: term(),
  transport_pid: term(),
  view: term()
}) :: {:ok, list()} | {:error, :not_found}

Lists user navigation history. In case if user is not found returns {:error, :not_found} tuple.

path_at(%Plug.Conn{}, number)

@callback path_at(
  %Plug.Conn{
    adapter: term(),
    assigns: term(),
    body_params: term(),
    cookies: term(),
    halted: term(),
    host: term(),
    method: term(),
    owner: term(),
    params: term(),
    path_info: term(),
    path_params: term(),
    port: term(),
    private: term(),
    query_params: term(),
    query_string: term(),
    remote_ip: term(),
    req_cookies: term(),
    req_headers: term(),
    request_path: term(),
    resp_body: term(),
    resp_cookies: term(),
    resp_headers: term(),
    scheme: term(),
    script_name: term(),
    secret_key_base: term(),
    state: term(),
    status: term()
  },
  number()
) :: {:ok, String.t()} | {:error, atom()}
@callback path_at(
  %Phoenix.LiveView.Socket{
    assigns: term(),
    endpoint: term(),
    fingerprints: term(),
    host_uri: term(),
    id: term(),
    parent_pid: term(),
    private: term(),
    redirected: term(),
    root_pid: term(),
    router: term(),
    sticky?: term(),
    transport_pid: term(),
    view: term()
  },
  number()
) :: {:ok, String.t()} | {:error, atom()}

Returns user's Nth last path. In case if user is not found returns an error tuple. In case if number exceeds the navigation history limit returns an error tuple. In case if number exceed the user's navigation history records number returns an error tuple.