Belt v0.5.1 Belt.Provider.Helpers View Source
Provides functions shared across providers.
Link to this section 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
Link to this section 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
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)"
Increments the key part of a path.
Example
iex> increment_path("/foo/bar.ext", 1)
"/foo/bar_1.ext"