Mix v1.0.5 Mix.Utils
Utilities used throughout Mix and tasks.
Summary
Functions
Converts the given string to CamelCase format
Take a command name and attempts to load a module
with the command name converted to a module name
in the given at scope
Takes a command and converts it to the module name format
Copies content from either a URL or a local filesystem path to target path
Extract files from a list of paths
Extract all stale sources compared to the given targets
Returns the date the given path was last modified
Get the mix home
Get all paths defined in the MIX_PATH env variable
Takes a module and converts it to a command
Prompts the user to overwrite the file if it exists. Returns the user input
Opens and reads content from either a URL or a local filesystem path and returns the contents as a binary
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
Converts the given atom or binary to underscore format
Functions
Converts the given string to CamelCase format.
Examples
iex> Mix.Utils.camelize "foo_bar"
"FooBar"
Take 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
iex> Mix.Utils.command_to_module("compile", Mix.Tasks)
{:module, Mix.Tasks.Compile}
Takes a command and converts it to the module name format.
Examples
iex> Mix.Utils.command_to_module_name("compile.elixir")
"Compile.Elixir"
Copies content from either a URL or a local filesystem path to target path.
Used by tasks like archive.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.
Options
:shell- Forces the use ofwgetorcurlto fetch the file if the given path is a URL.:force- Forces overwriting target file without a shell prompt.
Extract files from a list of paths.
exts_or_pattern may be a list of extensions or a
Path.wildcard/1 pattern.
If the path in paths is a file, it is included in
the return result. If it is a directory, it is searched
recursively for files with the given extensions or matching
the given patterns.
Returns the date the given path was last modified.
If the path does not exist, it returns the unix epoch (1970-01-01 00:00:00).
Get the mix home.
It defaults to ~/.mix unless the MIX_HOME
environment variable is set.
Developers should only store entries in the
MIX_HOME directory which are guaranteed to
work across multiple Elixir versions, as it is
not recommended to swap the MIX_HOME directory
as configuration and other important data may be
stored there.
Get all paths defined in the MIX_PATH env variable.
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
iex> Mix.Utils.module_name_to_command(Mix.Tasks.Compile, 2)
"compile"
iex> Mix.Utils.module_name_to_command("Mix.Tasks.Compile.Elixir", 2)
"compile.elixir"
Opens and reads content from either a URL or a local filesystem path and returns the contents as a binary.
Raises if the given path is not a URL, nor a file or if the file or URL are invalid.
Options
:shell- Forces the use ofwgetorcurlto fetch the file if the given path is a URL.
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
iex> Mix.Utils.underscore "FooBar"
"foo_bar"
iex> Mix.Utils.underscore "Foo.Bar"
"foo/bar"
iex> 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"