cupboard v0.2.0 Cupboard.Server View Source
Documentation for Cupboard.Server
API.
Cupboard.Server
stores and retrieves state in a process.
As is, Cupboard.Server
is not supervised; the assumption
being it will be used as a child component in a supervised application.
Link to this section Summary
Functions
Retrieve the currently stored state
Start the Cupboard.Server
with an empty list
as the default state, unless otherwise provided.
Update the currently stored state
Link to this section Functions
Retrieve the currently stored state
Example
iex>Cupboard.Server.start_link
iex>Cupboard.Server.get
[]
iex>Cupboard.Server.start_link {0,0}
iex>Cupboard.Server.get
{0,0}
Start the Cupboard.Server
with an empty list
as the default state, unless otherwise provided.
Example
iex>{:ok, pid} = Cupboard.Server.start_link
iex> is_pid(pid)
true
Update the currently stored state
Example
iex>Cupboard.Server.start_link
iex>Cupboard.Server.get
[]
iex>Cupboard.Server.update [1]
iex>Cupboard.Server.get
[1]
iex>Cupboard.Server.start_link {0,0}
iex>Cupboard.Server.get
{0,0}
iex>Cupboard.Server.update {0,1}
iex>Cupboard.Server.get
{0,1}
defmodule State, do: defstruct number: 0
iex>import State
iex>Cupboard.Server.start_link %State{}
iex>Cupboard.Server.get
%State{number: 0}
iex>Cupboard.Server.update %State{number: 1}
iex>Cupboard.Server.get
%State{number: 1}