elixir_leaderboard v0.1.5 ElixirLeaderboard.Storage behaviour View Source
Use this behaviour to implement your own leaderboard storage engines.
Link to this section Summary
Callbacks
Add a single entry to the leaderboard. Return an error if the entry is already in the leaderboard. The operation should be blocking
Atomically insert an entry, or update it if its id already exists in the leaderboard
Replace all data in the leaderboard with the data in the provided stream. Return immediately, perform most of the work asynchronously
Return a correctly ordered stream of bottom leaderboard records that can be accessed all the way to the top
Clear all the data in your leaderboard state
Show the number of records in the leaderboard
Create a leaderboard in your storage (keyword arguments are determined by storage needs). Return what needs to be persisted
Return a leaderboard record by its id. Return nil if not found
Return a list of records around the given id. The list should go from top to bottom if the range is increasing, and from bottom to top if range decreasing. Zero always corresponds to where the id is positioned
If supporting server/client mode: add a way to fetch the leaderboard stored in your GenServer's state
Replace all data in the leaderboard with the data in the provided stream. Block until completed
Remove a single entry from the leaderboard based on its id. Return an error if the id does not exist. The operation should be blocking
If supporting server/client mode: add a way to start the server and make sure to store the leaderboard struct in the state, since it will be needed for get_lb
Return a correctly ordered stream of top leaderboard records that can be accessed all the way to the bottom
Update a single entry in the leaderboard. Return an error if the entry is not found in the leaderboard. The operation should be blocking
Link to this section Callbacks
add(arg0, arg1, arg2)
View Source
add(
ElixirLeaderboard.Leaderboard.state(),
ElixirLeaderboard.Entry.t(),
ElixirLeaderboard.Indexer.t()
) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
add( ElixirLeaderboard.Leaderboard.state(), ElixirLeaderboard.Entry.t(), ElixirLeaderboard.Indexer.t() ) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
Add a single entry to the leaderboard. Return an error if the entry is already in the leaderboard. The operation should be blocking.
add_or_update(arg0, arg1, arg2)
View Source
add_or_update(
ElixirLeaderboard.Leaderboard.state(),
ElixirLeaderboard.Entry.t(),
ElixirLeaderboard.Indexer.t()
) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
add_or_update( ElixirLeaderboard.Leaderboard.state(), ElixirLeaderboard.Entry.t(), ElixirLeaderboard.Indexer.t() ) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
Atomically insert an entry, or update it if its id already exists in the leaderboard.
async_populate(arg0, arg1, arg2)
View Source
(optional)
async_populate(
ElixirLeaderboard.Leaderboard.state(),
Enumerable.t(),
ElixirLeaderboard.Indexer.t()
) :: {:ok, term()} | {:error, term()}
async_populate( ElixirLeaderboard.Leaderboard.state(), Enumerable.t(), ElixirLeaderboard.Indexer.t() ) :: {:ok, term()} | {:error, term()}
Replace all data in the leaderboard with the data in the provided stream. Return immediately, perform most of the work asynchronously.
bottom(arg0)
View Source
bottom(ElixirLeaderboard.Leaderboard.state()) :: Enumerable.t()
bottom(ElixirLeaderboard.Leaderboard.state()) :: Enumerable.t()
Return a correctly ordered stream of bottom leaderboard records that can be accessed all the way to the top.
clear(arg0)
View Source
clear(ElixirLeaderboard.Leaderboard.state()) ::
{:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
clear(ElixirLeaderboard.Leaderboard.state()) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
Clear all the data in your leaderboard state.
count(arg0)
View Source
count(ElixirLeaderboard.Leaderboard.state()) :: non_neg_integer()
count(ElixirLeaderboard.Leaderboard.state()) :: non_neg_integer()
Show the number of records in the leaderboard.
create(keyword)
View Source
create(keyword()) ::
{:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
create(keyword()) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
Create a leaderboard in your storage (keyword arguments are determined by storage needs). Return what needs to be persisted.
get(arg0, arg1)
View Source
get(ElixirLeaderboard.Leaderboard.state(), ElixirLeaderboard.Entry.id()) ::
ElixirLeaderboard.Record.t() | nil
get(ElixirLeaderboard.Leaderboard.state(), ElixirLeaderboard.Entry.id()) :: ElixirLeaderboard.Record.t() | nil
Return a leaderboard record by its id. Return nil if not found.
get(arg0, arg1, arg2)
View Source
get(
ElixirLeaderboard.Leaderboard.state(),
ElixirLeaderboard.Entry.id(),
Range.t()
) :: [ElixirLeaderboard.Record.t()]
get( ElixirLeaderboard.Leaderboard.state(), ElixirLeaderboard.Entry.id(), Range.t() ) :: [ElixirLeaderboard.Record.t()]
Return a list of records around the given id. The list should go from top to bottom if the range is increasing, and from bottom to top if range decreasing. Zero always corresponds to where the id is positioned.
For example:
- A range -2..1 should return (from top to bottom) 2 records prior to the given id, the record at the given id, and 1 record after the given id.
- A range 2..-2 should return (from bottom to top) 2 records after the given id, the record at the given id, and 2 records before the given id.
get_lb(atom)
View Source
(optional)
get_lb(atom()) :: ElixirLeaderboard.Leaderboard.t()
get_lb(atom()) :: ElixirLeaderboard.Leaderboard.t()
If supporting server/client mode: add a way to fetch the leaderboard stored in your GenServer's state.
populate(arg0, arg1, arg2)
View Source
populate(
ElixirLeaderboard.Leaderboard.state(),
Enumerable.t(),
ElixirLeaderboard.Indexer.t()
) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
populate( ElixirLeaderboard.Leaderboard.state(), Enumerable.t(), ElixirLeaderboard.Indexer.t() ) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
Replace all data in the leaderboard with the data in the provided stream. Block until completed.
remove(arg0, arg1, arg2)
View Source
remove(
ElixirLeaderboard.Leaderboard.state(),
ElixirLeaderboard.Entry.id(),
ElixirLeaderboard.Indexer.t()
) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
remove( ElixirLeaderboard.Leaderboard.state(), ElixirLeaderboard.Entry.id(), ElixirLeaderboard.Indexer.t() ) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
Remove a single entry from the leaderboard based on its id. Return an error if the id does not exist. The operation should be blocking.
start_link(arg0)
View Source
(optional)
start_link(ElixirLeaderboard.Leaderboard.t()) :: GenServer.on_start()
start_link(ElixirLeaderboard.Leaderboard.t()) :: GenServer.on_start()
If supporting server/client mode: add a way to start the server and make sure to store the leaderboard struct in the state, since it will be needed for get_lb.
top(arg0)
View Source
top(ElixirLeaderboard.Leaderboard.state()) :: Enumerable.t()
top(ElixirLeaderboard.Leaderboard.state()) :: Enumerable.t()
Return a correctly ordered stream of top leaderboard records that can be accessed all the way to the bottom.
update(arg0, arg1, arg2)
View Source
update(
ElixirLeaderboard.Leaderboard.state(),
ElixirLeaderboard.Entry.t(),
ElixirLeaderboard.Indexer.t()
) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
update( ElixirLeaderboard.Leaderboard.state(), ElixirLeaderboard.Entry.t(), ElixirLeaderboard.Indexer.t() ) :: {:ok, ElixirLeaderboard.Leaderboard.state()} | {:error, term()}
Update a single entry in the leaderboard. Return an error if the entry is not found in the leaderboard. The operation should be blocking.