UP | HOME

leptus_utils

Module

leptus_utils

This module provides a number of useful functions.

Functions

priv_dir/1

Finds the path to the priv directory in an application.

priv_dir(App) -> Dir | {error, bad_name}

App = atom()
Dir = file:name_all()

paginator/1

Generates a paginator function for paginating a list of elements.

paginator(NElementPerPage) -> fun((Page, Objects) -> Objects)

NElementPerPage = Page = non_neg_integer()
Objects = [any()]

Example:

1> Page = paginator(3).
2> Page(2, [1,2,3,4,5,6,7,8,9]).
[4,5,6]

paginate/3

Paginates a list of objects.

paginate(NElementPerPage, Objects, Page) -> Objects

NElementPerPage = Page = non_neg_integer()
Objects = [any()]

listener_bucket/1

Returns a running listener bucket that includes Handlers, Options and started date-time.

listener_bucket(Listener) -> Bucket | not_found

Listener = http | https | spdy
Bucket = #listener_bucket{}

listener_handlers/1

Returns handlers of a running listener.

listener_handlers(Listener) -> Handlers | {error, not_found}

Listener = http | https | spdy
Handlers = [{module(), State :: any()}]

Prints a running listener information, such as handlers, routes and allowed methods.

print_listener_info(Listener) -> ok

Listener = http | https | spdy

Author: Sina Samavati

Created: 2018-09-19