Convert from the retired ExFSWatch to FileSystem

Initial working commit. Use the new GenServer only API.
This commit is contained in:
Jeff Gandt
2017-12-13 09:39:54 -05:00
parent 0ee975cddd
commit 3742caf1b4
4 changed files with 16 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ defmodule ElixirKoans do
worker(Display, []),
worker(Tracker, []),
worker(Runner, []),
worker(Watcher, [])
worker(Watcher, [[]])
]
opts = [strategy: :one_for_one, name: ElixirKoans.Supervisor]

View File

@@ -1,14 +1,21 @@
defmodule Watcher do
use ExFSWatch, dirs: ["lib/koans"]
use GenServer
def start_link do
start()
def start_link(args) do
GenServer.start_link(__MODULE__, args)
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
file |> normalize |> reload
path |> normalize |> reload
end
{:noreply, state}
end
defp reload(file) do

View File

@@ -11,11 +11,11 @@ defmodule Koans.Mixfile do
def application do
[mod: {ElixirKoans, []},
applications: [:exfswatch, :logger]]
applications: [:file_system, :logger]]
end
defp deps do
[{:exfswatch, "~> 0.3"}]
[{:file_system, "~> 0.2"}]
end
defp elixirc_path(:test), do: ["lib/", "test/support"]

View File

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