arizona_reloader_rule (arizona v0.4.0)
View SourceRuns one dev-reloader rule: watches a directory through the configured
arizona_watcher implementation, filters the changed paths by the rule's
patterns, debounces bursts, and hands the resulting file list to the rule's
callback and the arizona_watcher pubsub topic.
arizona_reloader_sup runs one per rule of the reloader application env
(child_specs/1); see arizona_watcher for the config and the watcher
contract.
Usage
1> arizona_reloader_rule:start_link("/home/me/myapp/src", #{
watcher => arizona_watcher_fs,
patterns => [".*\\.erl$"],
debounce => 200,
callback => fun arizona_reloader:reload_erl/1
}).
{ok, <0.123.0>}Subscribers of the arizona_watcher pubsub topic receive
{arizona_watcher, Dir, Files} after each debounced burst, Dir being the
rule's absolute directory, so one subscriber can tell the rules apart.
Options
watcher-- thearizona_watcherimplementation: a module, or{Module, Opts}to pass it options (required)patterns-- list of regex strings to filter file paths (default[".*"])callback-- optionalfun([string()]) -> term()invoked synchronously with the changed file list before the broadcastdebounce-- milliseconds to wait after the last change before flushing (default100); coalesces editor-save bursts into a single event
Summary
Functions
The child specs for the reloader application env: one rule process per rule
when it holds enabled => true and a non-empty rules list, none otherwise.
Formats the reloader config errors child_specs/1 raises into an actionable
boot message. Picked up by erl_error:format_exception/3 via the error_info
annotation at the raise site.
Starts a rule process for Dir with the given options.
Types
Functions
-spec child_specs(Reloader) -> [supervisor:child_spec()] when Reloader :: map().
The child specs for the reloader application env: one rule process per rule
when it holds enabled => true and a non-empty rules list, none otherwise.
Raises a formatted error when there are rules to run but the watcher key is
missing, names a module that is not on the code path (the package providing it
is not a dependency of this build), or names one that does not implement
arizona_watcher, and when a rule has no directory.
-spec format_error(Reason, Stacktrace) -> ErrorInfo when Reason :: term(), Stacktrace :: [tuple()], ErrorInfo :: #{general := iolist()}.
Formats the reloader config errors child_specs/1 raises into an actionable
boot message. Picked up by erl_error:format_exception/3 via the error_info
annotation at the raise site.
-spec start_link(Dir, Opts) -> gen_server:start_ret() when Dir :: string(), Opts :: #{watcher := watcher(), _ => term()}.
Starts a rule process for Dir with the given options.
Errors with {not_a_directory, Dir} if the path is not an existing
directory.