View Source Igniter.Project.Module (igniter v0.3.49)

Codemods and utilities for interacting with modules

Summary

Types

Placement instruction for a module.

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. Raises an error if it doesn't exist

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.

Finds a module, raising an error if its not found.

Checks if a module is defined somewhere in the project. The returned 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

Determines where a module should be placed in a project.

Types

@type location_type() ::
  :source_folder | {:source_folder, String.t()} | :test | :test_support

Placement instruction for a module.

  • :source_folder - The first source folder of the project
  • {:source_folder, path} - The selected source folder, i.e "lib"
  • :test - Creating a test file
  • :test_support - Creating a test support file

Functions

Link to this function

create_module(igniter, module_name, contents, opts \\ [])

View Source

Creates a new file & module in its appropriate location.

Options

  • :location - A location type. See t:location_type for more.
Link to this function

find_all_matching_modules(igniter, predicate)

View Source
@spec find_all_matching_modules(igniter :: Igniter.t(), (module(),
                                                   Sourceror.Zipper.t() ->
                                                     boolean())) ::
  {Igniter.t(), [module()]}
Link to this function

find_and_update_module(igniter, module_name, updater)

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

Link to this function

find_and_update_module!(igniter, module_name, updater)

View Source
@spec find_and_update_module!(Igniter.t(), module(), (Sourceror.Zipper.t() ->
                                                  {:ok, Sourceror.Zipper.t()}
                                                  | :error)) ::
  Igniter.t()

Finds a module and updates its contents. Raises an error if it doesn't exist

Link to this function

find_and_update_or_create_module(igniter, module_name, contents, updater, opts \\ [])

View Source

Finds 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).
Link to this function

find_module(igniter, module_name)

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

Link to this function

find_module!(igniter, module_name)

View Source
@spec find_module!(Igniter.t(), module()) ::
  {Igniter.t(), Rewrite.Source.t(), Sourceror.Zipper.t()} | no_return()

Finds a module, raising an error if its not found.

See find_module/2 for more information.

Link to this function

module_exists(igniter, module_name)

View Source
@spec module_exists(Igniter.t(), module()) :: {boolean(), Igniter.t()}

Checks if a module is defined somewhere in the project. The returned igniter should not be discarded.

Link to this function

module_exists?(igniter, module_name)

View Source
This function is deprecated. Use `module_exists/2` instead..

Checks if a module is defined somewhere in the project. The returned igniter should not be discarded.

Link to this function

module_name(igniter, suffix)

View Source
@spec module_name(Igniter.t(), String.t()) :: module()

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

Link to this function

module_name_prefix(igniter)

View Source
@spec module_name_prefix(Igniter.t()) :: module()

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

Link to this function

proper_location(igniter, module_name, type \\ :source_folder)

View Source
@spec proper_location(Igniter.t(), module(), location_type()) :: String.t()

Determines where a module should be placed in a project.