View Source Igniter.Code.Module (igniter v0.3.16)
Utilities for working with Elixir modules
Summary
Functions
Creates a new file & module in its appropriate location.
Finds a module and updates its contents. Returns {:error, igniter}
if the module could not be found. Do not discard this igniter.
Finds a module and updates its contents wherever it is.
Finds a module, returning a new igniter, and the source and zipper location. This new igniter should not be discarded.
Checks if a module is defined somewhere in the project. The returned igniter should not be discarded.
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 a specific defmodule call
Moves the zipper to the body of a module that use
s 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
Creates a new file & module in its appropriate location.
@spec find_and_update_module(Igniter.t(), module(), (Sourceror.Zipper.t() -> {:ok, Sourceror.Zipper.t()} | :error)) :: {:ok, Igniter.t()} | {:error, Igniter.t()}
Finds a module and updates its contents. Returns {:error, igniter}
if the module could not be found. Do not discard this igniter.
find_and_update_or_create_module(igniter, module_name, contents, updater, opts \\ [])
View SourceFinds a module and updates its contents wherever it is.
If the module does not yet exist, it is created with the provided contents. In that case,
the path is determined with Igniter.Code.Module.proper_location/2
, but may optionally be overwritten with options below.
Options
:path
- Path where to create the module, relative to the project root. Default:nil
(uses:kind
to determine the path).
@spec find_module(Igniter.t(), module()) :: {:ok, {Igniter.t(), Rewrite.Source.t(), Sourceror.Zipper.t()}} | {:error, Igniter.t()}
Finds a module, returning a new igniter, and the source and zipper location. This new igniter should not be discarded.
In general, you should not use the returned source and zipper to update the module, instead, use this to interrogate
the contents or source in some way, and then call find_and_update_module/3
with a function to perform an update.
Checks if a module is defined somewhere in the project. The returned igniter should not be discarded.
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
@spec move_to_defmodule(Sourceror.Zipper.t()) :: {:ok, Sourceror.Zipper.t()} | :error
Moves the zipper to a defmodule call
@spec move_to_defmodule(Sourceror.Zipper.t(), module()) :: {:ok, Sourceror.Zipper.t()} | :error
Moves the zipper to a specific defmodule call
@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 use
s 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/".
Examples:
iex> Igniter.Code.Module.proper_location(MyApp.Hello) "lib/my_app/hello.ex"
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"
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"