Convert from the retired ExFSWatch to FileSystem
Initial working commit. Use the new GenServer only API.
This commit is contained in:
@@ -8,7 +8,7 @@ defmodule ElixirKoans do
|
|||||||
worker(Display, []),
|
worker(Display, []),
|
||||||
worker(Tracker, []),
|
worker(Tracker, []),
|
||||||
worker(Runner, []),
|
worker(Runner, []),
|
||||||
worker(Watcher, [])
|
worker(Watcher, [[]])
|
||||||
]
|
]
|
||||||
|
|
||||||
opts = [strategy: :one_for_one, name: ElixirKoans.Supervisor]
|
opts = [strategy: :one_for_one, name: ElixirKoans.Supervisor]
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
defmodule Watcher do
|
defmodule Watcher do
|
||||||
use ExFSWatch, dirs: ["lib/koans"]
|
use GenServer
|
||||||
|
|
||||||
def start_link do
|
def start_link(args) do
|
||||||
start()
|
GenServer.start_link(__MODULE__, args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def callback(file, events) do
|
def init(args) do
|
||||||
|
{:ok, watcher_pid} = FileSystem.start_link(dirs: ["lib/koans"])
|
||||||
|
FileSystem.subscribe(watcher_pid)
|
||||||
|
{:ok, %{watcher_pid: watcher_pid}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid}=state) do
|
||||||
if Enum.member?(events, :modified) do
|
if Enum.member?(events, :modified) do
|
||||||
file |> normalize |> reload
|
path |> normalize |> reload
|
||||||
end
|
end
|
||||||
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp reload(file) do
|
defp reload(file) do
|
||||||
|
|||||||
4
mix.exs
4
mix.exs
@@ -11,11 +11,11 @@ defmodule Koans.Mixfile do
|
|||||||
|
|
||||||
def application do
|
def application do
|
||||||
[mod: {ElixirKoans, []},
|
[mod: {ElixirKoans, []},
|
||||||
applications: [:exfswatch, :logger]]
|
applications: [:file_system, :logger]]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp deps do
|
defp deps do
|
||||||
[{:exfswatch, "~> 0.3"}]
|
[{:file_system, "~> 0.2"}]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp elixirc_path(:test), do: ["lib/", "test/support"]
|
defp elixirc_path(:test), do: ["lib/", "test/support"]
|
||||||
|
|||||||
3
mix.lock
3
mix.lock
@@ -1,2 +1 @@
|
|||||||
%{"exfswatch": {:hex, :exfswatch, "0.4.1", "008db817f6096eec69d17c7ca562c572fb4409728a09f465dea7e31190fb983c", [:mix], []},
|
%{"file_system": {:hex, :file_system, "0.2.2", "7f1e9de4746f4eb8a4ca8f2fbab582d84a4e40fa394cce7bfcb068b988625b06", [], [], "hexpm"}}
|
||||||
"fs": {:hex, :fs, "2.12.0", "ad631efacc9a5683c8eaa1b274e24fa64a1b8eb30747e9595b93bec7e492e25e", [:rebar3], []}}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user