A Reactor extension that provides steps for working with the local filesytem.
The following example uses Reactor to reverse all the files in the specified directory.
defmodule ReverseFilesInDirectory do
use Reactor, extensions: [Reactor.File]
input :directory
glob :all_files do
pattern input(:directory), transform: &Path.join(&1, "*")
end
map :reverse_files do
source result(:all_files)
read_file :read_file do
path element(:reverse_files)
end
step :reverse_content do
argument :content, result(:read_file)
run &{:ok, &String.reverse(&1.content)}
end
write_file :write_file do
path element(:reverse_files)
contents result(:reverse_content)
end
return :write_file
end
return :reverse_files
end
Reactor.run!(ReverseFilesInDirectory, %{directory: "./to_reverse"})
If available in Hex, the package can be installed
by adding reactor_file
to your list of dependencies in mix.exs
:
def deps do
[
{:reactor_file, "~> 0.18.3"}
]
end
Documentation for the latest release is available on HexDocs.
reactor
is licensed under the terms of the MIT
license. See the LICENSE
file in this
repository
for details.