Spur v0.4.0 Spur View Source

Simple activity tracking for Ecto-backed Elixir apps.

Link to this section Summary

Functions

Deletes the given Struct and an Spur.Activity record.

Inserts the given Struct and an Spur.Activity record.

Updates the given Struct and an Spur.Activity record.

Link to this section Functions

Link to this function

delete(trackable, func_or_params \\ %{}) View Source

Deletes the given Struct and an Spur.Activity record.

Examples

iex> trackable = %SpurTest.TrackableStruct{user: %SpurTest.AppUser{}} |> SpurTest.Repo.insert!
...> result = Spur.delete(trackable)
...> with {:ok, %SpurTest.TrackableStruct{}} <- result, do: :ok
:ok
Link to this function

insert(trackable, func_or_params \\ %{}) View Source

Inserts the given Struct and an Spur.Activity record.

Examples

iex> result = Spur.insert(%SpurTest.TrackableStruct{user: %SpurTest.AppUser{}})
...> with {:ok, %SpurTest.TrackableStruct{}} <- result, do: :ok
:ok

iex> result = Spur.insert(%SpurTest.TrackableStruct{})
...> with {:error, %Ecto.Changeset{}} <- result, do: :error
:error

iex> Spur.insert(%SpurTest.TrackableStruct{user: %SpurTest.AppUser{}}, %{object: "special-user"})
...> Spur.Activity |> where(object: "special-user") |> Repo.exists?
true

iex> Spur.insert(%SpurTest.TrackableStruct{user: %SpurTest.AppUser{name: "Buddy"}}, fn trackable, _params -> %{actor: trackable.user.name} end)
...> Spur.Activity |> where(actor: "Buddy") |> Repo.exists?
true
Link to this function

update(trackable, func_or_params \\ %{}) View Source

Updates the given Struct and an Spur.Activity record.

Examples

iex> trackable = %SpurTest.TrackableStruct{user: %SpurTest.AppUser{}} |> SpurTest.Repo.insert! |> Ecto.Changeset.change
...> result = Spur.update(trackable)
...> with {:ok, %SpurTest.TrackableStruct{}} <- result, do: :ok
:ok