Current section
Files
Jump to
Current section
Files
src/butterbee@internal@lib.erl
-module(butterbee@internal@lib).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/butterbee/internal/lib.gleam").
-export([single_element/1, toml_to_dynamic/1, dynamic_to_string/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.
?MODULEDOC(false).
-file("src/butterbee/internal/lib.gleam", 15).
?DOC(false).
-spec single_element(list(UXR)) -> {ok, UXR} | {error, binary()}.
single_element(List) ->
case List of
[Element] ->
{ok, Element};
[] ->
{error, <<"List is empty"/utf8>>};
_ ->
{error, <<"List has more than one element"/utf8>>}
end.
-file("src/butterbee/internal/lib.gleam", 24).
?DOC(false).
-spec toml_to_dynamic(tom:toml()) -> gleam@dynamic:dynamic_().
toml_to_dynamic(Value) ->
case Value of
{string, Value@1} ->
gleam_stdlib:identity(Value@1);
{int, Value@2} ->
gleam_stdlib:identity(Value@2);
{float, Value@3} ->
gleam_stdlib:identity(Value@3);
{bool, Value@4} ->
gleam_stdlib:identity(Value@4);
{array, Value@5} ->
erlang:list_to_tuple(
(gleam@list:map(Value@5, fun toml_to_dynamic/1))
);
{inline_table, Value@6} ->
gleam@dynamic:properties(
begin
_pipe = Value@6,
_pipe@1 = maps:to_list(_pipe),
gleam@list:map(
_pipe@1,
fun(Entry) ->
{Key, Value@7} = Entry,
{gleam_stdlib:identity(Key),
toml_to_dynamic(Value@7)}
end
)
end
);
{table, Value@6} ->
gleam@dynamic:properties(
begin
_pipe = Value@6,
_pipe@1 = maps:to_list(_pipe),
gleam@list:map(
_pipe@1,
fun(Entry) ->
{Key, Value@7} = Entry,
{gleam_stdlib:identity(Key),
toml_to_dynamic(Value@7)}
end
)
end
);
{array_of_tables, Value@8} ->
erlang:list_to_tuple(
(gleam@list:map(
Value@8,
fun(Table) -> toml_to_dynamic({table, Table}) end
))
);
_ ->
_pipe@2 = palabres:error(<<"Could not unwrap value"/utf8>>),
_pipe@3 = palabres:string(
_pipe@2,
<<"value"/utf8>>,
gleam@string:inspect(Value)
),
palabres:log(_pipe@3),
gleam_stdlib:identity(<<""/utf8>>)
end.
-file("src/butterbee/internal/lib.gleam", 54).
?DOC(false).
-spec dynamic_to_string(gleam@dynamic:dynamic_()) -> binary().
dynamic_to_string(Dyn) ->
case gleam_stdlib:classify_dynamic(Dyn) of
<<"String"/utf8>> ->
case gleam@dynamic@decode:run(
Dyn,
{decoder, fun gleam@dynamic@decode:decode_string/1}
) of
{ok, Str} ->
Str;
{error, _} ->
<<""/utf8>>
end;
<<"Int"/utf8>> ->
case gleam@dynamic@decode:run(
Dyn,
{decoder, fun gleam@dynamic@decode:decode_int/1}
) of
{ok, Int} ->
erlang:integer_to_binary(Int);
{error, _} ->
<<""/utf8>>
end;
<<"Float"/utf8>> ->
case gleam@dynamic@decode:run(
Dyn,
{decoder, fun gleam@dynamic@decode:decode_float/1}
) of
{ok, Float} ->
gleam_stdlib:float_to_string(Float);
{error, _} ->
<<""/utf8>>
end;
<<"Bool"/utf8>> ->
case gleam@dynamic@decode:run(
Dyn,
{decoder, fun gleam@dynamic@decode:decode_bool/1}
) of
{ok, Bool} ->
_pipe = gleam@bool:to_string(Bool),
string:lowercase(_pipe);
{error, _} ->
<<""/utf8>>
end;
_ ->
_pipe@1 = palabres:error(
<<"Could not convert dynamic to string"/utf8>>
),
_pipe@2 = palabres:string(
_pipe@1,
<<"value"/utf8>>,
gleam@string:inspect(Dyn)
),
palabres:log(_pipe@2),
<<""/utf8>>
end.