map_bot v0.1.0 MapBot View Source

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

Factories Definition:

Factories are defined in a single module such as:

defmodule MyApp.Factory do
  def new(:greenish), do: %{color: :green}
  def new(:tomato), do: %{name: "Tomato", color: :red}
  def new(MapBot.Car), do: %MapBot.Car{model: "SUV", color: :black}
  def new(:with_code), do: %{code: &"CODE-#{&1}"}
end

Configuration:

Then configure :map_bot to use that factories definition:

config :map_bot, factories: MyApp.Factory

And now you can start using the MapBot.build/2 function.

Link to this section Summary

Functions

Builds an Elixir Map/Struct

Link to this section Types

Link to this type attributes() View Source
attributes() :: map() | keyword()
Link to this type result() View Source
result() :: struct() | map()

Link to this section Functions

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

Builds an Elixir Map/Struct.

Examples

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

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

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

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

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