Bonfire.Social.FeedFilters.Atom (Bonfire v0.9.12-social-beta.71)

View Source

Custom Type to support :atom fields in Ecto schemas.

Example

defmodule Post do
  use Ecto.Schema

  schema "posts" do
    field :atom_field, Ecto.Atom
  end
end

Summary

Functions

Casts a value to an atom.

Loads an atom from database storage (stored as string).

Functions

cast(value)

Casts a value to an atom.

Examples

iex> Bonfire.Social.FeedFilters.Atom.cast(:my_atom)
{:ok, :my_atom}

iex> Bonfire.Social.FeedFilters.Atom.cast("existing_atom")
{:ok, :existing_atom}

iex> Bonfire.Social.FeedFilters.Atom.cast("a_non_existing_atom")
:error

iex> Bonfire.Social.FeedFilters.Atom.cast(123)
:error

Note: The "existing_atom" test will pass because :existing_atom is already used in this file.

load(value)

Loads an atom from database storage (stored as string).

Examples

iex> Bonfire.Social.FeedFilters.Atom.load("existing_atom")
{:ok, :existing_atom}

iex> Bonfire.Social.FeedFilters.Atom.load("another_non_existing_atom")
:error

iex> Bonfire.Social.FeedFilters.Atom.load(123)
:error

Note: The "existing_atom" test will pass because :existing_atom is already used in this file.