Adify v0.1.0 Adify.Environment

Represents the structure of an adification process. This represents the state of the system, intended state of the system and processes ran during adification.

Link to this section Summary

Functions

Returns the digest file content when given an environment

Initializes an Environment struct

Installs a tool and returns the updated environment

Installs all tools and returns the updated environment

Link to this section Types

Link to this type

t()
t() :: %Adify.Environment{
  confirm: term(),
  digest_file: term(),
  ended_at: term(),
  meta: term(),
  operations: term(),
  os: term(),
  started_at: term(),
  state: term(),
  tools: term(),
  tools_dir: term()
}

Link to this section Functions

Link to this function

changeset(struct, params)

Link to this function

digest_content(environment)
digest_content(Adify.Environment.t()) :: String.t()

Returns the digest file content when given an environment

Examples:

iex> options = [
...>   confirm: false,
...>   digest_file: ".temp.dump",
...>   tools_dir: "./test/support/tools/",
...>   os: "arch_linux"
...> ]
iex> {:ok, tool} =
...>   Adify.YAML.parse_and_cast("./test/support/tools/valid/201907051629/tool.yaml")
iex> tools = [tool]
iex> {:ok, env} = Adify.Environment.init(options)
iex> true = env.state == "new" && Enum.empty?(env.operations)
iex> {:ok, env} = Adify.Environment.install_tools(env)
iex> digest =Adify.Environment.digest_content(env)
iex> digest =~ "Started at" && digest =~ "State: completed"
true
Link to this function

init(opts \\ [])
init(Keyword.t()) :: {:ok, Adify.Environment.t()} | {:error, term()}

Initializes an Environment struct

## Examples
# When invalid options are given
iex> options = [
...>   confirm: true,
...>   digest_file: ".temp.dump",
...>   tools_dir: "./test/support/tools/",
...>   os: "arch_linux"
...> ]
iex> {:ok, tool} =
...>   Adify.YAML.parse_and_cast("./test/support/tools/valid/201907051629/tool.yaml")
iex> tools = [tool]
iex> {:ok, env} = Adify.Environment.init(options)
iex> env.confirm == true && env.ended_at == nil && env.state == "new" &&
...>  env.meta == %{} && env.tools == tools
true

# When invalid options are given
iex> options = [
...>   confirm: true,
...>   digest_file: ".temp.dump",
...>   tools_dir: "./test/support/tools/"
...> ]
iex> Adify.Environment.init(options)
{:error, [os: {"can't be blank", [validation: :required]}]}
Link to this function

install_tool(environment, tool)
install_tool(Adify.Environment.t(), Adify.Tool.t()) ::
  {:ok, term()} | {:error, term()}

Installs a tool and returns the updated environment

Examples:

# When tool is valid
iex> options = [
...>   confirm: false,
...>   digest_file: ".temp.dump",
...>   tools_dir: "./test/support/tools/",
...>   os: "arch_linux"
...> ]
iex> {:ok, tool} =
...>   Adify.YAML.parse_and_cast("./test/support/tools/valid/201907051629/tool.yaml")
iex> tools = [tool]
iex> {:ok, env} = Adify.Environment.init(options)
iex> true = env.state == "new" && Enum.empty?(env.operations)
iex> {:ok, env} = Adify.Environment.install_tool(env, tool)
iex> env.state == "processing" && !Enum.empty?(env.operations)
true
Link to this function

install_tools(environment)
install_tools(Adify.Environment.t()) :: {:ok, term()} | {:error, term()}

Installs all tools and returns the updated environment

Examples:

# When tool is valid
iex> options = [
...>   confirm: false,
...>   digest_file: ".temp.dump",
...>   tools_dir: "./test/support/tools/",
...>   os: "arch_linux"
...> ]
iex> {:ok, tool} =
...>   Adify.YAML.parse_and_cast("./test/support/tools/valid/201907051629/tool.yaml")
iex> tools = [tool]
iex> {:ok, env} = Adify.Environment.init(options)
iex> true = env.state == "new" && Enum.empty?(env.operations)
iex> {:ok, env} = Adify.Environment.install_tools(env)
iex> env.state == "completed" && !Enum.empty?(env.operations)
true