LowEndInsight v0.4.2 Helpers View Source
Collection of generic helper functions.
Link to this section Summary
Functions
convert_config_to_list/1: takes in Application.get_all_env(:app) and returns a list of maps, to be encoded as JSON. Since JSON doesn't have an equivalent tuple type the libs all bonk on encoding config values.
get_slug/1: extracts the slug from the provided URI argument and returns the path
split_slug/1: splits apart the username and repo from a git slug returning discrete stings.
validates field is a valid url
iex> ["http://www.google.com","http://www.test.com"] ...> |> Helpers.validate_urls() :ok
Link to this section Functions
convert_config_to_list/1: takes in Application.get_all_env(:app) and returns a list of maps, to be encoded as JSON. Since JSON doesn't have an equivalent tuple type the libs all bonk on encoding config values.
get_slug/1: extracts the slug from the provided URI argument and returns the path
Example
iex(1)> {:ok, slug} = Helpers.get_slug("https://github.com/kitplummer/xmpprails")
{:ok, "kitplummer/xmpprails"}
iex(2)> slug
"kitplummer/xmpprails"
split_slug/1: splits apart the username and repo from a git slug returning discrete stings.
Examples
iex(6)> {:ok, org, repo} = Helpers.split_slug("kitplummer/xmpprails")
{:ok, "kitplummer", "xmpprails"}
iex(7)> org
"kitplummer"
iex(8)> repo
"xmpprails"
validates field is a valid url
Examples
iex> "https:://www.url.com" ...> |> Helpers.validate_url()
iex> "http://zipbooks.com/" ...> |> Helpers.validate_url() :ok
iex> '"https://"https://www.google.com"' ...> |> Helpers.validate_url()
iex> "zipbooks.com" ...> |> Helpers.validate_url()
iex> "https://zipbooks..com" ...> |> Helpers.validate_url()
iex> ["http://www.google.com","http://www.test.com"] ...> |> Helpers.validate_urls() :ok
iex> ["https://zipbooks..com", "http://www.test.com"] ...> |> Helpers.validate_urls()
iex> ["https//github.com/kitplummer/xmpp4rails","https://www.zipbooks.com", "http://www.test.com"] ...> |> Helpers.validate_urls()
iex> "https://zipbooks.com" ...> |> Helpers.validate_urls()