Skip to content

Commit 3742caf

Browse files
committed
Convert from the retired ExFSWatch to FileSystem
Initial working commit. Use the new GenServer only API.
1 parent 0ee975c commit 3742caf

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

lib/elixir_koans.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule ElixirKoans do
88
worker(Display, []),
99
worker(Tracker, []),
1010
worker(Runner, []),
11-
worker(Watcher, [])
11+
worker(Watcher, [[]])
1212
]
1313

1414
opts = [strategy: :one_for_one, name: ElixirKoans.Supervisor]

lib/watcher.ex

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
defmodule Watcher do
2-
use ExFSWatch, dirs: ["lib/koans"]
2+
use GenServer
33

4-
def start_link do
5-
start()
4+
def start_link(args) do
5+
GenServer.start_link(__MODULE__, args)
66
end
77

8-
def callback(file, events) do
8+
def init(args) do
9+
{:ok, watcher_pid} = FileSystem.start_link(dirs: ["lib/koans"])
10+
FileSystem.subscribe(watcher_pid)
11+
{:ok, %{watcher_pid: watcher_pid}}
12+
end
13+
14+
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid}=state) do
915
if Enum.member?(events, :modified) do
10-
file |> normalize |> reload
16+
path |> normalize |> reload
1117
end
18+
{:noreply, state}
1219
end
1320

1421
defp reload(file) do

mix.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ defmodule Koans.Mixfile do
1111

1212
def application do
1313
[mod: {ElixirKoans, []},
14-
applications: [:exfswatch, :logger]]
14+
applications: [:file_system, :logger]]
1515
end
1616

1717
defp deps do
18-
[{:exfswatch, "~> 0.3"}]
18+
[{:file_system, "~> 0.2"}]
1919
end
2020

2121
defp elixirc_path(:test), do: ["lib/", "test/support"]

mix.lock

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
%{"exfswatch": {:hex, :exfswatch, "0.4.1", "008db817f6096eec69d17c7ca562c572fb4409728a09f465dea7e31190fb983c", [:mix], []},
2-
"fs": {:hex, :fs, "2.12.0", "ad631efacc9a5683c8eaa1b274e24fa64a1b8eb30747e9595b93bec7e492e25e", [:rebar3], []}}
1+
%{"file_system": {:hex, :file_system, "0.2.2", "7f1e9de4746f4eb8a4ca8f2fbab582d84a4e40fa394cce7bfcb068b988625b06", [], [], "hexpm"}}

0 commit comments

Comments
 (0)