Wayfinder.RoutesWatcher (Wayfinder Ex v0.1.1)

View Source

A GenServer that watches for changes to router files and regenerates routes.

Credit to: https://github.com/assimelha/routes/blob/master/lib/routes/watcher.ex

This module provides functionality to:

  • Watch for file system changes in the current working directory
  • Detect modifications to router.ex files
  • Automatically regenerate routes when router files change

Summary

Functions

Child spec for supervision tree.

Handles synchronous calls. Used for testing to ensure message processing is complete.

Handles file system events, specifically looking for router.ex file modifications.

Initializes the watcher by starting a FileSystem process and subscribing to events.

Starts the watcher process.

Functions

child_spec(init_arg)

Child spec for supervision tree.

compile_router(router_path, compiler_fun)

handle_call(msg, from, state)

Handles synchronous calls. Used for testing to ensure message processing is complete.

handle_info(msg, state)

Handles file system events, specifically looking for router.ex file modifications.

init(opts)

Initializes the watcher by starting a FileSystem process and subscribing to events.

start_link(opts \\ [])

Starts the watcher process.

Options

  • :generator_module - Module to use for route generation (defaults to Wayfinder)
  • :compiler_fun - Function to call when compiling router files (optional)

Accepts GenServer options. The process will be registered under the module name.