View Source CloudflareApi.Utils (cloudflare_api v0.0.4)
Link to this section Summary
Functions
Macro that makes a function public in test, private in non-test
Quick regex check to see if the supplied string
is a valid UUID
Takes a list of strings or atoms and returns a list with string and atoms.
Convert a map to a String
, suitable for printing.
Checks if the passed item is nil or empty string.
Easy drop-in to a pipe to inspect the return value of the previous function.
if value
(value of the argument) is nil, this will raise CloudflareApi.CantBeNil
if value
(value of the argument) is nil, this will raise CloudflareApi.CantBeNil
Converts a struct to a regular map by deleting the :__meta__
key
Generate a new UUIDv4
Link to this section Functions
Macro that makes a function public in test, private in non-test
Quick regex check to see if the supplied string
is a valid UUID
Check is done by simple regular expression and is not overly sophisticated.
Return true || false
Examples
iex> CloudflareApi.Utils.is_uuid?(nil)
false
iex> CloudflareApi.Utils.is_uuid?("hello world")
false
iex> CloudflareApi.Utils.is_uuid?("4c2fd8d3-a6e3-4e4b-a2ce-3f21456eeb85")
true
Takes a list of strings or atoms and returns a list with string and atoms.
Examples
iex> list_to_strings_and_atoms([:circle])
[:circle, "circle"]
iex> list_to_strings_and_atoms([:circle, :square])
[:square, "square", :circle, "circle"]
iex> list_to_strings_and_atoms(["circle", "square"])
["square", :square, "circle", :circle]
Convert a map with String
keys into a map with Atom
keys.
Examples
iex> CloudflareApi.Utils.map_atom_keys_to_strings(%{one: "one", two: "two"})
%{"one" => "one", "two" => "two"}
Convert a map with String
keys into a map with Atom
keys.
Examples
iex> CloudflareApi.Utils.map_string_keys_to_atoms(%{"one" => "one", "two" => "two"})
%{one: "one", two: "two"}m
Convert a map to a String
, suitable for printing.
Optionally pass a list of keys to mask.
Examples
iex> map_to_string(%{michael: "knight"})
"michael: 'knight'"
iex> map_to_string(%{michael: "knight", kitt: "karr"})
"kitt: 'karr', michael: 'knight'"
iex> map_to_string(%{michael: "knight", kitt: "karr"}, [:kitt])
"kitt: '****', michael: 'knight'"
iex> map_to_string(%{michael: "knight", kitt: "karr"}, [:kitt, :michael])
"kitt: '****', michael: '******'"
iex> map_to_string(%{"michael" => "knight", "kitt" => "karr", "carr" => "hart"}, ["kitt", "michael"])
"carr: 'hart', kitt: '****', michael: '******'"
Checks if the passed item is nil or empty string.
The param will be passed to to_string()
and then String.trim()
and checked for empty string
Examples
iex> CloudflareApi.Utils.nil_or_empty?("hello")
false
iex> CloudflareApi.Utils.nil_or_empty?("")
true
iex> CloudflareApi.Utils.nil_or_empty?(nil)
true
pry_pipe(retval, arg1 \\ nil, arg2 \\ nil, arg3 \\ nil, arg4 \\ nil)
View SourceEasy drop-in to a pipe to inspect the return value of the previous function.
Examples
conn
|> put_status(:not_found)
|> put_view(CloudflareApiWeb.ErrorView)
|> render(:"404")
|> pry_pipe()
if value
(value of the argument) is nil, this will raise CloudflareApi.CantBeNil
argn
(name of the argument) will be passed to allow for more helpful error
messages that tell you the name of the variable that was nil
Examples
iex> CloudflareApi.Utils.raise_if_nil!("someval")
"someval"
iex> CloudflareApi.Utils.raise_if_nil!(nil)
** (CloudflareApi.CantBeNil) variable 'somevar' was nil but cannot be
(malan 0.1.0) lib/malan/utils.ex:142: CloudflareApi.Utils.raise_if_nil!/1
if value
(value of the argument) is nil, this will raise CloudflareApi.CantBeNil
argn
(name of the argument) will be passed to allow for more helpful error
messages that tell you the name of the variable that was nil
Examples
iex> CloudflareApi.Utils.raise_if_nil!("somevar", "someval")
"someval"
iex> CloudflareApi.Utils.raise_if_nil!("somevar", nil)
** (CloudflareApi.CantBeNil) variable 'somevar' was nil but cannot be
(malan 0.1.0) lib/malan/utils.ex:135: CloudflareApi.Utils.raise_if_nil!/2
Converts a struct to a regular map by deleting the :__meta__
key
Examples
CloudflareApi.Utils.struct_to_map(%Something{hello: "world"})
%{hello: "world"}
Generate a new UUIDv4
Examples
CloudflareApi.Utils.uuidgen()
"4c2fd8d3-a6e3-4e4b-a2ce-3f21456eeb85"