View Source Bonfire.Epics.Epic (Bonfire v0.9.10-classic-beta.169)

Represents and manages an Epic, which is a sequence of Acts to be executed.

An Epic is a struct containing lists of previous and next steps, errors, and assigns.

This module provides functionality to create, modify, and run Epics, as well as handle errors and debugging.

Summary

Types

t()

Represents an Epic struct.

Functions

Adds an error to the Epic.

Appends Act(s) to the end of the Epic's next steps.

Assigns a value to the Epic's assigns.

Loads an epic from the app's config.

Creates an Epic from a specification of steps.

Creates a new Epic with the given list of next steps.

Prepends Act(s) to the beginning of the Epic's next steps.

Renders all errors in the Epic as a string.

Runs the Epic, executing each Act in sequence (with some Acts optionally running in parallel).

Updates an assign in the Epic using a function.

Types

@type t() :: %Bonfire.Epics.Epic{
  assigns: %{optional(atom()) => any()},
  errors: [any()],
  next: [Bonfire.Epics.Act.t()],
  prev: [Bonfire.Epics.Act.t()]
}

Represents an Epic struct.

  • :prev - List of Acts that have already been run.
  • :next - List of remaining Acts to be run (may be modified during run).
  • :errors - List of errors (accrued during run).
  • :assigns - Map of assigned values (may be modified during run).

Functions

Adds an error to the Epic.

Parameters

  • epic: The Epic struct.
  • error: The Error struct to add.

Examples

iex> epic = %Bonfire.Epics.Epic{}
iex> error = %Bonfire.Epics.Error{error: "Something went wrong"}
iex> Bonfire.Epics.Epic.add_error(epic, error)
%Bonfire.Epics.Epic{errors: [%Bonfire.Epics.Error{error: "Something went wrong"}]}
Link to this function

add_error(epic, act, error, source \\ nil, stacktrace \\ nil)

View Source

Appends Act(s) to the end of the Epic's next steps.

Parameters

  • self: The Epic struct.
  • acts: A list of Acts or a single Act to append.

Examples

iex> epic = %Bonfire.Epics.Epic{next: [Act1]}
iex> Bonfire.Epics.Epic.append(epic, [Act2])
%Bonfire.Epics.Epic{next: [Act1, Act2]}
Link to this function

assign(self, name, value)

View Source

Assigns a value to the Epic's assigns.

Parameters

  • self: The Epic struct.
  • name: The atom key for the assign.
  • value: The value to assign.

Examples

iex> epic = %Bonfire.Epics.Epic{}
iex> Bonfire.Epics.Epic.assign(epic, :foo, "bar")
%Bonfire.Epics.Epic{assigns: %{foo: "bar"}}
Link to this macro

debug(epic, thing, label \\ "")

View Source (macro)
Link to this function

from_config!(config_key, name)

View Source

Loads an epic from the app's config.

Parameters

  • config_key: The config key to load, such as a module atom (in which case it will load it from that module's app config).
  • name: The name atom of the epic in the config.

Examples

iex> Bonfire.Epics.Epic.from_config!(MyApp.Module, :my_epic)
%Bonfire.Epics.Epic{...}

iex> Bonfire.Epics.Epic.from_config!(:my_key, :my_other_epic)
%Bonfire.Epics.Epic{...}

Creates an Epic from a specification of steps.

Parameters

  • acts: A list of act specifications.

Examples

iex> Bonfire.Epics.Epic.from_spec!([MyAct, {OtherAct, [option: :value]}])
%Bonfire.Epics.Epic{...}
Link to this macro

maybe_debug(epic, thing, label \\ "")

View Source (macro)

Creates a new Epic with the given list of next steps.

Parameters

  • next: A list of Acts to be executed.

Examples

iex> Bonfire.Epics.Epic.new([MyAct, OtherAct])
%Bonfire.Epics.Epic{next: [MyAct, OtherAct]}

Prepends Act(s) to the beginning of the Epic's next steps.

Parameters

  • self: The Epic struct.
  • acts: A list of Acts or a single Act to prepend.

Examples

iex> epic = %Bonfire.Epics.Epic{next: [Act2]}
iex> Bonfire.Epics.Epic.prepend(epic, [Act1])
%Bonfire.Epics.Epic{next: [Act1, Act2]}

Renders all errors in the Epic as a string.

Parameters

  • epic: The Epic struct containing errors.

Examples

iex> epic = %Bonfire.Epics.Epic{errors: [%Bonfire.Epics.Error{error: "Error 1"}, %Bonfire.Epics.Error{error: "Error 2"}]}
iex> Bonfire.Epics.Epic.render_errors(epic)
"Error 1\nError 2"

Runs the Epic, executing each Act in sequence (with some Acts optionally running in parallel).

Parameters

  • epic: The Epic struct to run.

Examples

iex> epic = Bonfire.Epics.Epic.new([MyAct, OtherAct])
iex> Bonfire.Epics.Epic.run(epic)
%Bonfire.Epics.Epic{prev: [OtherAct, MyAct], next: [], ...}
Link to this function

update(self, name, default, fun)

View Source

Updates an assign in the Epic using a function.

Parameters

  • self: The Epic struct.
  • name: The atom key for the assign.
  • default: The default value if the assign doesn't exist.
  • fun: The function to apply to the current value.

Examples

iex> epic = %Bonfire.Epics.Epic{assigns: %{count: 1}}
iex> Bonfire.Epics.Epic.update(epic, :count, 0, &(&1 + 1))
%Bonfire.Epics.Epic{assigns: %{count: 2}}