Adify v0.1.0 Adify.YAML

API to do all YAML operations for Adify

Link to this section Summary

Functions

Parses a YAML file for a tool and casts it to a struct, running all the ecto validations

Recursively convert all string keys to atom keys in a map

Link to this section Functions

Link to this function

parse_and_cast(tool_yaml_path)
parse_and_cast(Path.t()) :: {:ok, Adify.Tool.t()} | {:error, term()}

Parses a YAML file for a tool and casts it to a struct, running all the ecto validations

Examples:

# When the YAML file is a valid file:
iex> path =
...>   File.cwd!()
...>   |> Path.join("test/support/tools/valid/201907051629/tool.yaml")
iex> {:ok, %Adify.Tool{version: vsn}} = Adify.YAML.parse_and_cast(path)
iex> vsn
201907051629

# When the YAML file is not valid
iex> path =
...>   File.cwd!()
...>   |> Path.join("test/support/invalid.yaml")
iex> {:errors, errors} = Adify.YAML.parse_and_cast(path)
iex> errors
[os_commands: {"can't be blank", [validation: :required]},
  version: {"is invalid", [type: :integer, validation: :cast]}]

Recursively convert all string keys to atom keys in a map

Examples:

# When params is a map
iex> Adify.YAML.to_params(%{"key" => "value"})
%{key: "value"}

# When params is a list
iex> Adify.YAML.to_params([%{key: "value"}, %{"key" => "value"}])
[%{key: "value"}, %{key: "value"}]

# When params is something else
iex> Adify.YAML.to_params(:something_else)
:something_else