Mix v1.1.1 Mix.Utils
Utilities used throughout Mix and tasks.
Summary
Functions
Converts the given string to CamelCase format
Prompts the user to overwrite the file if it exists. Returns the user input
Takes 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
Extracts files from a list of paths
Extracts all stale sources
compared to the given targets
Returns the date the given path was last modified
Gets the Mix home
Gets all paths defined in the MIX_PATH env variable
Takes a module and converts it to a command
Opens and reads content from either a URL or a local filesystem path
and returns the contents as a {:ok, binary}
, :badpath
for invalid
paths or {:local, message}
for local errors and {:remote, message}
for remote ones
Returns true
if any of the sources
are stale
compared to the given targets
Symlinks directory source
to target
or copies 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"
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
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"
Extracts 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).
Gets 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.
Gets 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"
Specs
Opens and reads content from either a URL or a local filesystem path
and returns the contents as a {:ok, binary}
, :badpath
for invalid
paths or {:local, message}
for local errors and {:remote, message}
for remote ones.
Options
:sha512
- checks against the given sha512 checksum. Returns{:checksum, message}
in case it fails
Returns true
if any of the sources
are stale
compared to the given targets
.
Symlinks directory source
to target
or copies it recursively
in case symlink fails.
Expects 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:
iex> Mix.Utils.underscore "SAPExample"
"sap_example"
iex> Mix.Utils.camelize "sap_example"
"SapExample"