Packages

A type-safe configuration loader for Gleam that supports JSON, YAML, and TOML with automatic format detection, environment variable resolution, and profile-based configuration.

Current section

Files

Jump to
yodel src yodel@internal@format.erl
Raw

src/yodel@internal@format.erl

-module(yodel@internal@format).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yodel/internal/format.gleam").
-export([get_format/4]).
-export_type([format_detector/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 format_detector() :: {format_detector,
binary(),
fun((yodel@internal@input:input()) -> yodel@options:format())}.
-file("src/yodel/internal/format.gleam", 39).
?DOC(false).
-spec detect_format(yodel@internal@input:input(), list(format_detector())) -> yodel@options:format().
detect_format(Input, Formats) ->
gleam@list:fold(Formats, auto, fun(Acc, Format) -> case Acc of
auto ->
(erlang:element(3, Format))(Input);
_ ->
Acc
end end).
-file("src/yodel/internal/format.gleam", 20).
?DOC(false).
-spec get_format(
binary(),
binary(),
yodel@options:options(),
list(format_detector())
) -> yodel@options:format().
get_format(Input, Content, Options, Formats) ->
case yodel@options:get_format(Options) of
auto ->
case begin
_pipe = Input,
_pipe@1 = yodel@internal@input:detect_input(_pipe),
detect_format(_pipe@1, Formats)
end of
auto ->
_pipe@2 = Content,
_pipe@3 = yodel@internal@input:detect_input(_pipe@2),
detect_format(_pipe@3, Formats);
Format ->
Format
end;
Format@1 ->
Format@1
end.