Faker Elixir (octopus) v0.4.0 FakerElixir.Helper
Provide useful helpers
Summary
Functions
Will iterate through the enumerable as a constant cycle. Really useful when you want to seed your database with a pre-defined cycle
Fill a pattern with random letters
Fill a pattern with random number
Pick randomly a value in an enumerable
Functions
Will iterate through the enumerable as a constant cycle. Really useful when you want to seed your database with a pre-defined cycle
Warning:
The id (first param given) should be unique for each different cycle
Examples
Basic
iex(1)> FakerElixir.Helper.cycle(:zombies, ["Peter", "Audrey", "Laurent", "Frank"])
"Peter"
iex(2)> FakerElixir.Helper.cycle(:zombies, ["Peter", "Audrey", "Laurent", "Frank"])
"Audrey"
iex(3)> FakerElixir.Helper.cycle(:zombies, ["Peter", "Audrey", "Laurent", "Frank"])
"Laurent"
iex(4)> FakerElixir.Helper.cycle(:zombies, ["Peter", "Audrey", "Laurent", "Frank"])
"Frank"
iex(5)> FakerElixir.Helper.cycle(:zombies, ["Peter", "Audrey", "Laurent", "Frank"])
"Peter"
iex(6)> FakerElixir.Helper.cycle(:zombies, ["Peter", "Audrey", "Laurent", "Frank"])
"Audrey"
iex(7)> FakerElixir.Helper.cycle(:zombies, ["Peter", "Audrey", "Laurent", "Frank"])
"Laurent"
iex(8)> FakerElixir.Helper.cycle(:zombies, ["Peter", "Audrey", "Laurent", "Frank"])
"Frank"
# ... and so on.
Seed example
defmodule Seed do
alias FakerElixir.Helper
def make do
warriors = Stream.repeatedly(fn() -> fixture(:warrior) end)
|> Enum.take(5)
end
defp fixture(:warrior) do
%{
name: Helper.cycle(:name, ["anubis", "zeus", "behamut"]),
lvl: Helper.cycle(:lvl, [10, 25, 90])
}
end
end
iex> Seed.make
[
%{lvl: 10, name: "anubis"},
%{lvl: 25, name: "zeus"},
%{lvl: 90, name: "behamut"},
%{lvl: 10, name: "anubis"},
%{lvl: 25, name: "zeus"}
]
Fill a pattern with random letters
Examples
iex > FakerElixir.Helper.letterify("###")
"ahh"
iex > FakerElixir.Helper.letterify("#.#.#.#")
"k.e.n.u"
Fill a pattern with random number
Examples
iex > FakerElixir.Helper.numerify("Apt. ###")
"Apt. 902"
iex > FakerElixir.Helper.numerify("06.##.##.##.##")
"06.67.18.21.27"