Mix.Utils
Utilities used throughout Mix and tasks.
Conversions
This module handles two types of conversions:
From command names to module names, i.e. how the command
deps.gettranslates toDeps.Getand vice-versa;From underscore to CamelCase, i.e. how the file path
my_projecttranslates toMyProject;
Summary
| camelize(arg1) | Converts the given string to CamelCase format |
| command_to_module(command, at \\ Elixir) | Takes a |
| command_to_module_name(s) | Takes a command and converts it to the module name format |
| config_merge(old, new) | Merges two configs recursively, merging keyword lists and concatenating normal lists |
| extract_files(paths, exts_or_pattern) | Extract files from a list of paths |
| extract_stale(sources, targets) | Extract all stale |
| mix_home() | Gets the mix home. It defaults to |
| mix_paths() | Gets all extra paths defined in the environment variable
|
| module_name_to_command(module, nesting \\ 0) | Takes a module and converts it to a command. The nesting argument can be given in order to remove the nesting of a module |
| read_manifest(file) | Reads the given file as a manifest and returns each entry as a list |
| read_path!(path) | Opens and reads content from either a URL or a local filesystem path |
| stale?(sources, targets) | Returns |
| symlink_or_copy(source, target) | Symlink directory |
| underscore(atom) | Converts the given atom or binary to underscore format |
| write_manifest(file, entries) | Writes a manifest file with the given |
Functions
Converts the given string to CamelCase format.
Examples
Mix.Utils.camelize "foo_bar" #=> "FooBar"
Takes a command name and attempts to load a module
with the command name converted to a module name
in the given at scope.
Returns { :module, module } in case a module
exists and is loaded, { :error, reason } otherwise.
Examples
Mix.Utils.command_to_module("compile", Mix.Tasks)
#=> { :module, Mix.Tasks.Compile }
Takes a command and converts it to the module name format.
Examples
command_to_module_name("compile.elixir")
#=> "Compile.Elixir"
Merges two configs recursively, merging keyword lists and concatenating normal lists.
Extract files from a list of paths.
If any of the paths is a directory, the directory is looped recursively searching for the given extensions or the given pattern. When looking up directories, files starting with "." are ignored.
Extract all stale sources compared to the given targets.
Gets the mix home. It defaults to ~/.mix unless the
MIX_HOME environment variable is set.
Gets all extra paths defined in the environment variable
MIX_PATH. MIX_PATH may contain multiple paths. If on Windows,
those paths should be separated by ;, if on unix systems,
use :.
Takes a module and converts it to a command. The nesting argument can be given in order to remove the nesting of a module.
Examples
module_name_to_command(Mix.Tasks.Compile, 2)
#=> "compile"
module_name_to_command("Mix.Tasks.Compile.Elixir", 2)
#=> "compile.elixir"
Reads the given file as a manifest and returns each entry as a list.
A manifest is a tabular file where each line is a row and each entry in a row is separated by "\t". The first entry must always be a path to a compiled artifact.
In case there is no manifest file, returns an empty list.
Opens and reads content from either a URL or a local filesystem path.
Used by tasks like local.install and local.rebar that support
installation either from a URL or a local file.
Raises if the given path is not a url, nor a file or if the file or url are invalid.
Returns true if any of the sources are stale
compared to the given targets.
Symlink directory source to target or copy it recursively
in case symlink fails. Expect source and target to be absolute
paths as it generates a relative symlink.
Converts the given atom or binary to underscore format.
If an atom is given, it is assumed to be an Elixir module, so it is converted to a binary and then processed.
Examples
Mix.Utils.underscore "FooBar" #=> "foo_bar"
Mix.Utils.underscore "Foo.Bar" #=> "foo/bar"
Mix.Utils.underscore Foo.Bar #=> "foo/bar"
In general, underscore can be thought of as the reverse of
camelize, however, in some cases formatting may be lost:
Mix.Utils.underscore "SAPExample" #=> "sap_example"
Mix.Utils.camelize "sap_example" #=> "SapExample"