View Source Igniter (igniter v0.3.57)

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 notice to the notices list. Notices are displayed to the user once the igniter finishes running.

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.

Applies the current changes to the mix.exs in the Igniter and fetches dependencies.

Stores the key/value pair in igniter.assigns

Returns true if the igniter or source provided has changed

Returns true if any of the files specified in paths have changed.

Finds the Igniter.Mix.Task task by name and composes it (calls its igniter/2) into the current igniter. If the task doesn't exist, a fallback implementation may be provided as the last argument.

Copies an EEx template file from the source path to the target path.

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

Creates the given file in the project with the provided string contents, or updates it with a function of type zipper_updater() if it already exists.

Creates the given file in the project with the provided string contents, or updates it with a function as in update_file/3 (or with zipper_updater() for elixir files) if it already exists.

Executes or dry-runs a given Igniter.

Checks if a file exists on the file system or in the igniter.

Returns whether the current Igniter has pending changes.

This function stores in the igniter if its been run before, so it is only run once, which is expensive.

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()],
  moves: %{optional(String.t()) => String.t()},
  notices: [String.t()],
  rewrite: Rewrite.t(),
  tasks: [String.t() | {String.t(), [String.t()]}],
  warnings: [String.t()]
}
@type zipper_updater() :: (Sourceror.Zipper.t() ->
                       {:ok, Sourceror.Zipper.t()}
                       | {:error, String.t() | [String.t()]})

Functions

Link to this function

add_issue(igniter, issue)

View Source
@spec add_issue(t(), term() | [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_notice(igniter, notice)

View Source
@spec add_notice(t(), String.t()) :: t()

Adds a notice to the notices list. Notices are displayed to the user once the igniter finishes running.

Link to this function

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

View Source

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)

View Source
@spec add_warning(t(), term() | [term()]) :: t()

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

Link to this function

apply_and_fetch_dependencies(igniter, opts \\ [])

View Source

Applies the current changes to the mix.exs in the Igniter and fetches dependencies.

Returns the remaining changes in the Igniter if successful.

Options

  • :error_on_abort? - If true, raises an error if the user aborts the operation. Returns the original igniter if not.
  • :yes - If true, automatically applies the changes without prompting the user.
Link to this function

assign(igniter, key_vals)

View Source
Link to this function

assign(igniter, key, value)

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

Stores the key/value pair in igniter.assigns

@spec changed?(t() | Rewrite.Source.t()) :: boolean()

Returns true if the igniter or source provided has changed

Link to this function

changed?(igniter, paths)

View Source
@spec changed?(t(), String.t() | [String.t()]) :: boolean()

Returns true if any of the files specified in paths have changed.

Link to this function

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

View Source

Finds the Igniter.Mix.Task task by name and composes it (calls its igniter/2) into the current igniter. If the task doesn't exist, a fallback implementation may be provided as the last argument.

Link to this function

copy_template(igniter, source, target, assigns, opts \\ [])

View Source
@spec copy_template(
  igniter :: t(),
  source :: Path.t(),
  target :: Path.t(),
  assigns :: Keyword.t(),
  opts :: Keyword.t()
) :: t()

Copies an EEx template file from the source path to the target path.

Accepts the same options as create_new_file/4.

Link to this function

create_new_elixir_file(igniter, path, contents \\ "", opts \\ [])

View Source
This function is deprecated. Use `create_new_file/4`.
Link to this function

create_new_file(igniter, path, contents \\ "", opts \\ [])

View Source

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

Options

  • :on_exists - The action to take if the file already exists. Can be
    • :error (default) - Adds an error that prevents any eventual write.
    • :warning - Warns when writing but continues (without overwriting)
    • :skip - Skips writing the file without a warning
    • :overwrite - Warns when writing and overwrites the content with the new content
Link to this function

create_or_update_elixir_file(igniter, path, contents, updater)

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

Creates the given file in the project with the provided string contents, or updates it with a function of type zipper_updater() if it already exists.

Link to this function

create_or_update_file(igniter, path, contents, updater)

View Source

Creates the given file in the project with the provided string contents, or updates it with a function as in update_file/3 (or with zipper_updater() for elixir files) if it already exists.

Link to this function

do_or_dry_run(igniter, opts \\ [])

View Source

Executes or dry-runs a given Igniter.

@spec exists?(t(), Path.t()) :: boolean()

Checks if a file exists on the file system or in the igniter.

Link to this function

has_changes?(igniter, paths \\ nil)

View Source

Returns whether the current Igniter has pending changes.

Link to this function

include_all_elixir_files(igniter)

View Source

This function stores in the igniter if its been run before, so it is only run once, which is expensive.

Link to this function

include_existing_elixir_file(igniter, path, opts \\ [])

View Source
This function is deprecated. Use `include_existing_file/3` instead.
@spec include_existing_elixir_file(t(), Path.t(), opts :: Keyword.t()) :: t()
Link to this function

include_existing_file(igniter, path, opts \\ [])

View Source
@spec include_existing_file(t(), Path.t(), opts :: Keyword.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)

View Source
@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 \\ "")

View Source
This function is deprecated. Use `include_or_create_file/3` instead.
@spec include_or_create_elixir_file(t(), Path.t(), contents :: String.t()) :: t()
Link to this function

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

View Source
@spec include_or_create_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.

Link to this function

move_file(igniter, from, from, opts \\ [])

View Source
@spec new() :: t()

Returns a new igniter

Link to this function

update_assign(igniter, key, default, fun)

View Source
Link to this function

update_elixir_file(igniter, path, func)

View Source
@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, updater, opts \\ [])

View Source

Updates a given file's Rewrite.Source

Link to this function

update_glob(igniter, glob, func)

View Source
@spec update_glob(
  t(),
  Path.t() | GlobEx.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.