Igniter (igniter v0.1.5)

Tools for generating and patching code into an Elixir project.

Summary

Functions

Adds an issue to the issues list. Any issues will prevent writing and be displayed to the user.

Adds a task to the tasks list. Tasks will be run after all changes have been commited

Adds a warning to the warnings list. Warnings will not prevent writing, but will be displayed to the user.

Stores the key/value pair in igniter.assigns

Finds the Igniter.Mix.Task task by name and composes it (calls its igniter/2) into the current igniter.

Creates a new elixir file in the project with the provided contents. Adds an error if it already exists.

Updates or creates the given file in the project with the provided contents.

Executes or dry-runs a given Igniter.

Includes the given file in the project, expecting it to exist. Does nothing if its already been added.

Includes all files matching the given glob, expecting them all (for now) to be elixir files.

Includes or creates the given file in the project with the provided contents. Does nothing if its already been added.

Returns a new igniter

Updates the source code of the given elixir file

Updates all files matching the given glob with the given zipper function.

Types

@type t() :: %Igniter{
  assigns: map(),
  issues: [String.t()],
  rewrite: Rewrite.t(),
  tasks: [{String.t() | [String.t()]}],
  warnings: [String.t()]
}
Link to this type

zipper_updater()

@type zipper_updater() :: (Sourceror.Zipper.t() ->
                       {:ok, Sourceror.Zipper.t()}
                       | {:error, String.t() | [String.t()]})

Functions

Link to this function

add_issue(igniter, issue)

@spec add_issue(t(), term()) :: t()

Adds an issue to the issues list. Any issues will prevent writing and be displayed to the user.

Link to this function

add_task(igniter, task, argv \\ [])

Adds a task to the tasks list. Tasks will be run after all changes have been commited

Link to this function

add_warning(igniter, warning)

Adds a warning to the warnings list. Warnings will not prevent writing, but will be displayed to the user.

Link to this function

assign(igniter, key_vals)

Link to this function

assign(igniter, key, value)

@spec assign(t(), atom(), term()) :: t()

Stores the key/value pair in igniter.assigns

Link to this function

compose_task(igniter, task, argv \\ [])

Finds the Igniter.Mix.Task task by name and composes it (calls its igniter/2) into the current igniter.

Link to this function

create_new_elixir_file(igniter, path, contents \\ "")

@spec create_new_elixir_file(t(), Path.t(), String.t()) :: t()

Creates a new elixir file in the project with the provided contents. Adds an error if it already exists.

Link to this function

create_or_update_elixir_file(igniter, path, contents, func)

@spec create_or_update_elixir_file(t(), Path.t(), String.t(), zipper_updater()) :: t()

Updates or creates the given file in the project with the provided contents.

Link to this function

do_or_dry_run(igniter, argv, opts \\ [])

Executes or dry-runs a given Igniter.

This takes argv to parameterize it as it is generally invoked from a mix task.

Link to this function

include_existing_elixir_file(igniter, path)

@spec include_existing_elixir_file(t(), Path.t()) :: t()

Includes the given file in the project, expecting it to exist. Does nothing if its already been added.

Link to this function

include_glob(igniter, glob)

@spec include_glob(t(), Path.t() | GlobEx.t()) :: t()

Includes all files matching the given glob, expecting them all (for now) to be elixir files.

Link to this function

include_or_create_elixir_file(igniter, path, contents \\ "")

@spec include_or_create_elixir_file(t(), Path.t(), contents :: String.t()) :: t()

Includes or creates the given file in the project with the provided contents. Does nothing if its already been added.

@spec new() :: t()

Returns a new igniter

Link to this function

update_elixir_file(igniter, path, func)

@spec update_elixir_file(t(), Path.t(), zipper_updater()) :: t()

Updates the source code of the given elixir file

Link to this function

update_file(igniter, path, func)

@spec update_file(t(), Path.t(), (Rewrite.Source.t() -> Rewrite.Source.t())) :: t()

Updates a given file's Rewrite.Source

Link to this function

update_glob(igniter, glob, func)

@spec update_glob(
  t(),
  Path.t(),
  zipper_updater()
) :: t()

Updates all files matching the given glob with the given zipper function.

Adds any new files matching that glob to the igniter first.