View Source Igniter.Code.Module (igniter v0.2.4)

Utilities for working with Elixir modules

Summary

Functions

Finds a module and updates its contents wherever it is. If it does not exist, it is created with the provided contents.

Given a suffix, returns a module name with the prefix of the current project.

The module name prefix based on the mix project's module name

Moves the zipper to a defmodule call

Moves the zipper to the body of a module that uses the provided module (or one of the provided modules).

Moves the zipper to the use statement for a provided module.

Parses a string into a module name

Returns the idiomatic file location for a given module, starting with "lib/".

Returns the test file location for a given module, according to mix test expectations, starting with "test/" and ending with "_test.exs".

Returns the test support location for a given module, starting with "test/support/" and dropping the module name prefix in the path.

Functions

Link to this function

find_and_update_or_create_module(igniter, module_name, contents, updater, path \\ nil)

View Source

Finds a module and updates its contents wherever it is. If it does not exist, it is created with the provided contents.

@spec module_name(String.t()) :: module()

Given a suffix, returns a module name with the prefix of the current project.

@spec module_name_prefix() :: module()

The module name prefix based on the mix project's module name

Link to this function

move_to_def(zipper, fun, arity)

View Source
Link to this function

move_to_defmodule(zipper)

View Source
@spec move_to_defmodule(Sourceror.Zipper.t()) :: {:ok, Sourceror.Zipper.t()} | :error

Moves the zipper to a defmodule call

Link to this function

move_to_defp(zipper, fun, arity)

View Source
Link to this function

move_to_module_using(zipper, one_of_modules)

View Source
@spec move_to_module_using(Sourceror.Zipper.t(), module() | [module()]) ::
  {:ok, Sourceror.Zipper.t()} | :error

Moves the zipper to the body of a module that uses the provided module (or one of the provided modules).

Link to this function

move_to_use(zipper, module)

View Source

Moves the zipper to the use statement for a provided module.

@spec parse(String.t()) :: module()

Parses a string into a module name

Link to this function

proper_location(module_name)

View Source
@spec proper_location(module()) :: Path.t()

Returns the idiomatic file location for a given module, starting with "lib/".

Examples:

iex> Igniter.Code.Module.proper_location(MyApp.Hello) "lib/my_app/hello.ex"

Link to this function

proper_test_location(module_name)

View Source
@spec proper_test_location(module()) :: Path.t()

Returns the test file location for a given module, according to mix test expectations, starting with "test/" and ending with "_test.exs".

Examples:

iex> Igniter.Code.Module.proper_test_location(MyApp.Hello) "test/my_app/hello_test.exs"

iex> Igniter.Code.Module.proper_test_location(MyApp.HelloTest) "test/my_app/hello_test.exs"

Link to this function

proper_test_support_location(module_name)

View Source
@spec proper_test_support_location(module()) :: Path.t()

Returns the test support location for a given module, starting with "test/support/" and dropping the module name prefix in the path.

Examples:

iex> Igniter.Code.Module.proper_test_support_location(MyApp.DataCase) "test/support/data_case.ex"