View Source DeepSinker (deep_sinker v1.0.0)
Customizable file traverser.
Link to this section Summary
Types
State of traversing.
Link to this section Types
@type filepath() :: String.t()
@type item_path() :: String.t()
@type item_type() :: :file | :directory | :ignore
@type new_option() :: {:order, order()}
@type next_option() :: {:handler, handler()}
@type next_result() :: {:ok, filepath()} | :done
@type order() :: :asc | :desc
@type t() :: %DeepSinker{ found_but_not_used_yet_items: [item_path()], order: order(), root_items: [item_path()] }
State of traversing.
Link to this section Functions
@spec new([item_path()], [new_option()]) :: t()
Create initial state.
examples
Examples
iex> DeepSinker.new(["/path/to/dir1", "/path/to/dir2"])
...> |> is_struct(DeepSinker)
true
iex> DeepSinker.new(["/path/to/dir1", "/path/to/dir2"], order: :desc)
...> |> is_struct(DeepSinker)
true
@spec next(t(), [next_option()]) :: {t(), next_result()}
Pop file and update state.
examples
Examples
iex> DeepSinker.new(["./"])
...> |> DeepSinker.next()
...> # {state, {:ok, filepath}} | {state, :done}
iex> DeepSinker.new(["./"])
...> |> DeepSinker.next(
...> handler: fn item_path ->
...> cond do
...> String.ends_with?(item_path, ".git") -> :ignore
...> String.contains?(item_path, ".") -> :file
...> true -> :directory
...> end
...> end
...> )
...> # {state, {:ok, filepath}} | {state, :done}
@spec stream(t(), [next_option()]) :: Enumerable.t(filepath())
Stream filepaths.
examples
Examples
iex> DeepSinker.new(["./"])
...> # |> DeepSinker.stream()
...> # |> Enum.to_list()
...> # ["list", "of" "filepaths"]
iex> DeepSinker.new(["./"])
...> |> DeepSinker.stream(
...> handler: fn item_path ->
...> cond do
...> String.ends_with?(item_path, ".git") -> :ignore
...> String.contains?(item_path, ".") -> :file
...> true -> :directory
...> end
...> end
...> )
...> # ["list", "of" "filepaths"]