./ct_report/coverage/mongoose_graphql_cowboy_response.COVER.html

1 -module(mongoose_graphql_cowboy_response).
2
3 -export([term_to_json/1]).
4
5 term_to_json(Term) ->
6 203 jiffy:encode(fixup(Term)).
7
8 %% Ground types
9 18 fixup(Term) when is_number(Term) -> Term;
10 917 fixup(Term) when is_atom(Term) -> Term;
11 1080 fixup(Term) when is_binary(Term) -> Term;
12 %% Compound types
13 fixup(Term) when is_list(Term) ->
14 214 [fixup(T) || T <- Term];
15 fixup(Term) when is_map(Term) ->
16 835 KVs = maps:to_list(Term),
17 835 maps:from_list([{fixup_key(K), fixup(V)} || {K, V} <- KVs]);
18 fixup(Term) ->
19 %% Every other term is transformed into a binary value
20 26 iolist_to_binary(
21 io_lib:format("~p", [Term])).
22
23 fixup_key(Term) ->
24 1285 case fixup(Term) of
25 T when is_binary(T) ->
26 541 T;
27 T ->
28 744 iolist_to_binary(io_lib:format("~p", [T]))
29 end.
30
Line Hits Source