./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 37 jiffy:encode(fixup(Term)).
7
8 %% Ground types
9 3 fixup(Term) when is_number(Term) -> Term;
10 131 fixup(Term) when is_atom(Term) -> Term;
11 166 fixup(Term) when is_binary(Term) -> Term;
12 %% Compound types
13 fixup(Term) when is_list(Term) ->
14 28 [fixup(T) || T <- Term];
15 fixup(Term) when is_map(Term) ->
16 144 KVs = maps:to_list(Term),
17 144 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 9 iolist_to_binary(
21 io_lib:format("~p", [Term])).
22
23 fixup_key(Term) ->
24 202 case fixup(Term) of
25 T when is_binary(T) ->
26 100 T;
27 T ->
28 102 iolist_to_binary(io_lib:format("~p", [T]))
29 end.
30
Line Hits Source