Skip to content

Instantly share code, notes, and snippets.

@alco
Created August 28, 2014 12:37
Show Gist options
  • Save alco/7bb0170574be797fb5f0 to your computer and use it in GitHub Desktop.
Save alco/7bb0170574be797fb5f0 to your computer and use it in GitHub Desktop.
data_path = Path.expand(Path.join(__DIR__, "../../priv/address.json"))
json = File.read!(data_path) |> JSEX.decode!
Enum.each json, fn(el) ->
{lang, data} = el
Enum.each data, fn
{"values", values} ->
Enum.each values, fn({fun, list}) ->
@get_fn String.to_atom("get_#{fun}")
@count_fn String.to_atom("#{fun}_count")
@lang String.to_atom(lang)
def unquote(String.to_atom(fun))() do
unquote(@get_fn)(Faker.locale, :crypto.rand_uniform(0, unquote(@count_fn)(Faker.locale)))
end
defp unquote(@count_fn)(@lang) do
unquote(Enum.count(list))
end
Enum.with_index(list) |> Enum.each fn({el, index}) ->
defp unquote(@get_fn)(@lang, unquote(index)) do
unquote(el)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment