Belt v0.1.7 Belt.Provider.Helpers
Provides functions shared across providers.
Summary
Functions
Ensures path
is included in a directory
Creates a Belt.FileInfo
struct from a local file
Increments a key name
Increments the key part of a path
Splits a key into its base name and extension
Functions
Ensures path
is included in a directory
.
Returns the original path as {:ok, path}
or an error tuple.
Example
iex> ensure_included("/foo/bar/buzz", "/foo/bar")
{:ok, "/foo/bar/buzz"}
iex> ensure_included("./foo", ".")
{:ok, "./foo"}
iex> {:error = s, _reason} = ensure_included("/usr", "."); s
:error
get_local_file_info(path, hashes \\ [])
get_local_file_info(Path.t, list) :: %Belt.FileInfo{config: term, hashes: term, identifier: term, modified: term, size: term, url: term}
Creates a Belt.FileInfo
struct from a local file.
Increments a key name.
Returns the given key
incremented by increment
steps using an optional fun
.
fun
receives the parameters base
, ext
and increment
.
Examples
iex> increment_key("foo.tar.gz", 1)
"foo_1.tar.gz"
iex> increment_key("foo.bar", 0)
"foo.bar"
iex> increment_key("foo", 1)
"foo_1"
iex> increment_key("foo.bar", 1, fn(base, ext, increment) ->
...> base <> ext <> " (#{increment})"
...> end)
"foo.bar (1)"