-module(automata@event@builtin@filter).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/automata/event/builtin/filter.gleam").
-export([is_scheduled/0, by_schedule_kind/1, by_plan_id/1, is_file_event/0, is_file_with_op/1, is_manual/0, is_custom/0, by_custom_kind/1, by_path_prefix/1, by_path_suffix/1, by_path_contains/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/automata/event/builtin/filter.gleam", 9).
?DOC(" Match any event whose body is `Scheduled(_, _, _)`.\n").
-spec is_scheduled() -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
is_scheduled() ->
automata@event@filter:on_body(fun(B) -> case B of
{scheduled, _, _, _} ->
true;
_ ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 19).
?DOC(" Match scheduled events whose `schedule_kind` equals `kind`.\n").
-spec by_schedule_kind(automata@event@builtin@body:schedule_kind()) -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
by_schedule_kind(Kind) ->
automata@event@filter:on_body(fun(B) -> case B of
{scheduled, _, _, K} ->
K =:= Kind;
_ ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 29).
?DOC(" Match scheduled events whose `plan_id` equals `id`.\n").
-spec by_plan_id(binary()) -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
by_plan_id(Id) ->
automata@event@filter:on_body(fun(B) -> case B of
{scheduled, Plan, _, _} ->
Plan =:= Id;
_ ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 39).
?DOC(" Match any `FileSystem(_)` body, irrespective of op.\n").
-spec is_file_event() -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
is_file_event() ->
automata@event@filter:on_body(fun(B) -> case B of
{file_system, _} ->
true;
_ ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 51).
?DOC(
" Match `FileSystem(_)` bodies whose wrapped `WatchEvent` carries\n"
" `op`. Replaces the legacy `is_file_created/modified/deleted/renamed`\n"
" helpers.\n"
).
-spec is_file_with_op(automata@fsevent@ast:op()) -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
is_file_with_op(Op) ->
automata@event@filter:on_body(fun(B) -> case B of
{file_system, Watch_event} ->
automata@fsevent@event:event_has(Watch_event, Op);
_ ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 92).
-spec is_manual() -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
is_manual() ->
automata@event@filter:on_body(fun(B) -> case B of
{manual, _, _} ->
true;
_ ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 101).
-spec is_custom() -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
is_custom() ->
automata@event@filter:on_body(fun(B) -> case B of
{custom, _, _} ->
true;
_ ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 110).
-spec by_custom_kind(binary()) -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
by_custom_kind(Kind) ->
automata@event@filter:on_body(fun(B) -> case B of
{custom, Name, _} ->
Name =:= Kind;
_ ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 119).
-spec file_path(automata@event@builtin@body:event_body()) -> {ok, binary()} |
{error, nil}.
file_path(B) ->
case B of
{file_system, Watch_event} ->
{ok,
automata@fsevent@path:path_to_string(
automata@fsevent@event:event_path(Watch_event)
)};
_ ->
{error, nil}
end.
-file("src/automata/event/builtin/filter.gleam", 63).
?DOC(
" Match `FileSystem(_)` events whose path starts with `prefix`.\n"
" `prefix` is matched against the canonical string rendering of the\n"
" event's path (the new path for renames).\n"
).
-spec by_path_prefix(binary()) -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
by_path_prefix(Prefix) ->
automata@event@filter:on_body(fun(B) -> case file_path(B) of
{ok, P} ->
gleam_stdlib:string_starts_with(P, Prefix);
{error, _} ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 73).
?DOC(" Match `FileSystem(_)` events whose path ends with `suffix`.\n").
-spec by_path_suffix(binary()) -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
by_path_suffix(Suffix) ->
automata@event@filter:on_body(fun(B) -> case file_path(B) of
{ok, P} ->
gleam_stdlib:string_ends_with(P, Suffix);
{error, _} ->
false
end end).
-file("src/automata/event/builtin/filter.gleam", 83).
?DOC(" Match `FileSystem(_)` events whose path contains `needle`.\n").
-spec by_path_contains(binary()) -> automata@event@filter:filter(automata@event@builtin@body:event_body()).
by_path_contains(Needle) ->
automata@event@filter:on_body(fun(B) -> case file_path(B) of
{ok, P} ->
gleam_stdlib:contains_string(P, Needle);
{error, _} ->
false
end end).