MapBot v1.0.0 MapBot behaviour View Source

MapBot builds and creates Elixir Maps/Structs based on factory definitions and attributes.

If you want to check how MapBot should be installed, configured and used please check this out.

In summary you should create your own Factory module such as this:

defmodule YourApp.Factory do
  use MapBot

  @impl MapBot
  def repo(), do: Repo

  @impl MapBot
  def new(YouyApp.Car), do: %YouyApp.Car{model: "SUV", color: :black}
  def new(:greenish), do: %{color: :green}
  def new(:tomato), do: %{name: "Tomato", color: :red}
  def new(:with_code_and_ref), do: %{code: &"CODE-#{&1}", reference: &"REF-#{&1}"}
end

For building your own maps and structs take a look on the functions MapBot.build/4, MapBot.create/4 and MapBot.create!/4.

Link to this section Summary

Functions

Builds an Elixir Map or Struct

Creates an Elixir Map or Struct using your Repo.insert/1

Creates an Elixir Map or Struct using your Repo.insert!/1

Link to this section Types

Link to this section Functions

Link to this function build(factory, name, traits \\ [], attrs \\ []) View Source
build(factory(), name(), traits(), attributes()) :: result()

Builds an Elixir Map or Struct.

Examples

iex> YourApp.Factory.build(:tomato)
%{name: "Tomato", color: :red}

iex> YourApp.Factory.build(YourApp.Car)
%YourApp.Car{model: "SUV", color: :black}

iex> YourApp.Factory.build(:tomato, color: :green)
%{name: "Tomato", color: :green}

iex> YourApp.Factory.build(:tomato, %{color: :green})
%{name: "Tomato", color: :green}

iex> YourApp.Factory.build(YourApp.Car, color: :yellow)
%YourApp.Car{model: "SUV", color: :yellow}

iex> YourApp.Factory.build(YourApp.Car, %{color: :yellow})
%YourApp.Car{model: "SUV", color: :yellow}

iex> YourApp.Factory.build(YourApp.Car, [:greenish])
%YourApp.Car{model: "SUV", color: :green}

iex> YourApp.Factory.build(YourApp.Car, [:greenish], model: "Sport")
%YourApp.Car{model: "Sport", color: :green}

iex> YourApp.Factory.build(YourApp.Car, [:greenish, model: "Sport"])
%YourApp.Car{model: "Sport", color: :green}
Link to this function create(factory, name, traits \\ [], attrs \\ []) View Source
create(factory(), name(), traits(), attributes()) :: {:ok, result()}

Creates an Elixir Map or Struct using your Repo.insert/1

Examples

iex> YourApp.Factory.create(YourApp.Car, color: :yellow)
{:ok, %YourApp.Car{id: "123", model: "SUV", color: :yellow}}
Link to this function create!(factory, name, traits \\ [], attrs \\ []) View Source
create!(factory(), name(), traits(), attributes()) :: result()

Creates an Elixir Map or Struct using your Repo.insert!/1

Examples

iex> YourApp.Factory.create!(YourApp.Car, color: :yellow)
%YourApp.Car{id: "123", model: "SUV", color: :yellow}

Link to this section Callbacks