Current section
Files
Jump to
Current section
Files
src/handles@internal@ctx_utils.erl
-module(handles@internal@ctx_utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/handles/internal/ctx_utils.gleam").
-export([get/3, get_property/3, get_list/3, get_bool/3]).
-export_type([drill_error/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-type drill_error() :: unknown_property | {unexpected_type, binary()}.
-file("src/handles/internal/ctx_utils.gleam", 13).
?DOC(false).
-spec drill_ctx(list(binary()), handles@ctx:value()) -> {ok,
handles@ctx:value()} |
{error, drill_error()}.
drill_ctx(Path, Ctx) ->
case Path of
[] ->
{ok, Ctx};
[Key | Rest] ->
case Ctx of
{dict, Arr} ->
case gleam@list:find(
Arr,
fun(It) -> erlang:element(2, It) =:= Key end
) of
{ok, {prop, _, Value}} ->
drill_ctx(Rest, Value);
{error, _} ->
{error, unknown_property}
end;
{list, _} ->
{error, {unexpected_type, <<"List"/utf8>>}};
{str, _} ->
{error, {unexpected_type, <<"Str"/utf8>>}};
{int, _} ->
{error, {unexpected_type, <<"Int"/utf8>>}};
{float, _} ->
{error, {unexpected_type, <<"Float"/utf8>>}};
{bool, _} ->
{error, {unexpected_type, <<"Bool"/utf8>>}}
end
end.
-file("src/handles/internal/ctx_utils.gleam", 36).
?DOC(false).
-spec get(list(binary()), handles@ctx:value(), integer()) -> {ok,
handles@ctx:value()} |
{error, handles@error:runtime_error()}.
get(Path, Ctx, Index) ->
_pipe = drill_ctx(Path, Ctx),
gleam@result:map_error(_pipe, fun(Err) -> case Err of
{unexpected_type, Got} ->
{unexpected_type, Index, Path, Got, [<<"Dict"/utf8>>]};
unknown_property ->
{unknown_property, Index, Path}
end end).
-file("src/handles/internal/ctx_utils.gleam", 46).
?DOC(false).
-spec get_property(list(binary()), handles@ctx:value(), integer()) -> {ok,
binary()} |
{error, handles@error:runtime_error()}.
get_property(Path, Root_ctx, Index) ->
_pipe = get(Path, Root_ctx, Index),
gleam@result:'try'(_pipe, fun(It) -> case It of
{str, Value} ->
{ok, Value};
{int, Value@1} ->
_pipe@1 = Value@1,
_pipe@2 = erlang:integer_to_binary(_pipe@1),
{ok, _pipe@2};
{float, Value@2} ->
_pipe@3 = Value@2,
_pipe@4 = gleam_stdlib:float_to_string(_pipe@3),
{ok, _pipe@4};
{list, _} ->
_pipe@5 = {unexpected_type,
Index,
Path,
<<"List"/utf8>>,
[<<"Str"/utf8>>, <<"Int"/utf8>>, <<"Float"/utf8>>]},
{error, _pipe@5};
{dict, _} ->
_pipe@6 = {unexpected_type,
Index,
Path,
<<"Dict"/utf8>>,
[<<"Str"/utf8>>, <<"Int"/utf8>>, <<"Float"/utf8>>]},
{error, _pipe@6};
{bool, _} ->
_pipe@7 = {unexpected_type,
Index,
Path,
<<"Bool"/utf8>>,
[<<"Str"/utf8>>, <<"Int"/utf8>>, <<"Float"/utf8>>]},
{error, _pipe@7}
end end).
-file("src/handles/internal/ctx_utils.gleam", 76).
?DOC(false).
-spec get_list(list(binary()), handles@ctx:value(), integer()) -> {ok,
list(handles@ctx:value())} |
{error, handles@error:runtime_error()}.
get_list(Path, Root_ctx, Index) ->
_pipe = get(Path, Root_ctx, Index),
gleam@result:'try'(_pipe, fun(It) -> case It of
{list, Value} ->
{ok, Value};
{str, _} ->
_pipe@1 = {unexpected_type,
Index,
Path,
<<"Str"/utf8>>,
[<<"List"/utf8>>]},
{error, _pipe@1};
{int, _} ->
_pipe@2 = {unexpected_type,
Index,
Path,
<<"Int"/utf8>>,
[<<"List"/utf8>>]},
{error, _pipe@2};
{bool, _} ->
_pipe@3 = {unexpected_type,
Index,
Path,
<<"Bool"/utf8>>,
[<<"List"/utf8>>]},
{error, _pipe@3};
{float, _} ->
_pipe@4 = {unexpected_type,
Index,
Path,
<<"Float"/utf8>>,
[<<"List"/utf8>>]},
{error, _pipe@4};
{dict, _} ->
_pipe@5 = {unexpected_type,
Index,
Path,
<<"Dict"/utf8>>,
[<<"List"/utf8>>]},
{error, _pipe@5}
end end).
-file("src/handles/internal/ctx_utils.gleam", 104).
?DOC(false).
-spec get_bool(list(binary()), handles@ctx:value(), integer()) -> {ok,
boolean()} |
{error, handles@error:runtime_error()}.
get_bool(Path, Root_ctx, Index) ->
_pipe = get(Path, Root_ctx, Index),
gleam@result:'try'(_pipe, fun(It) -> case It of
{bool, Value} ->
{ok, Value};
{list, _} ->
_pipe@1 = {unexpected_type,
Index,
Path,
<<"List"/utf8>>,
[<<"Bool"/utf8>>]},
{error, _pipe@1};
{str, _} ->
_pipe@2 = {unexpected_type,
Index,
Path,
<<"Str"/utf8>>,
[<<"Bool"/utf8>>]},
{error, _pipe@2};
{int, _} ->
_pipe@3 = {unexpected_type,
Index,
Path,
<<"Int"/utf8>>,
[<<"Bool"/utf8>>]},
{error, _pipe@3};
{float, _} ->
_pipe@4 = {unexpected_type,
Index,
Path,
<<"Float"/utf8>>,
[<<"Bool"/utf8>>]},
{error, _pipe@4};
{dict, _} ->
_pipe@5 = {unexpected_type,
Index,
Path,
<<"Dict"/utf8>>,
[<<"Bool"/utf8>>]},
{error, _pipe@5}
end end).