Skip to content
Permalink
Browse files
swap meanings of 'all' and 'none' in field limits
  • Loading branch information
bartekgorny committed Jul 25, 2018
1 parent 7e736d7 commit 61a0aff3a23d0b747798c2b0077fb3400e104271
Showing 2 changed files with 13 additions and 10 deletions.
@@ -79,7 +79,10 @@ get_list() ->
Lst = lists:map(fun make_list_entry/1, ets:tab2list(ets_table_name())),
lists:sort(Lst).

%% @doc Limit output to selected fields of a record (can be 'all', 'none', a field or a list of fields).
%% @doc Limit output to selected fields of a record (can be 'none', 'all', a field or a list of fields).
%% Limit set to 'none' means there is no limit, and all fields are displayed; limit 'all' means that
%% all fields are squashed and only record name will be shown.
%% @end
-spec limit(record_name(), arity(), limit()) -> ok | {error, record_unknown}.
limit(Name, Arity, Limit) ->
case lookup_record(Name, Arity) of
@@ -104,7 +107,7 @@ format_tuple(Tuple) ->

make_list_entry({{Name, _}, Fields, Module, Limits}) ->
FmtLimit = case Limits of
[] -> all;
[] -> none;
Other -> Other
end,
{Module, Name, Fields, FmtLimit}.
@@ -161,7 +164,7 @@ ensure_table_exists() ->
ets_table_name() -> recon_record_definitions.

rec_info({Name, Fields}, Module) ->
{{Name, length(Fields)}, field_names(Fields), Module, all}.
{{Name, length(Fields)}, field_names(Fields), Module, none}.

rem_for_module({_, _, Module, _} = Rec, Module) ->
ets:delete_object(ets_table_name(), Rec);
@@ -214,8 +217,8 @@ format_record(Rec, {{Name, Arity}, Fields, _, Limits}) ->
format_kv(Key, Val) ->
[recon_lib:format_trace_output(true, Key), "=", recon_lib:format_trace_output(true, Val)].

apply_limits(List, all) -> List;
apply_limits(_List, none) -> [];
apply_limits(List, none) -> List;
apply_limits(_List, all) -> [];
apply_limits(List, Field) when is_atom(Field) ->
[{Field, proplists:get_value(Field, List)}, {more, '...'}];
apply_limits(List, Limits) ->
@@ -51,17 +51,17 @@ lists_and_limits(_Config) ->
recon_rec:import(records1),
recon_rec:import(records2),
List = recon_rec:get_list(),
[{records1,another,[ddd,eee,fff],all},
{records1,state,[aaa,bbb,ccc],all},
{records2,another,[one,two,three,four],all}] = List,
[{records1,another,[ddd,eee,fff],none},
{records1,state,[aaa,bbb,ccc],none},
{records2,another,[one,two,three,four],none}] = List,
recon_rec:limit(another, 3, ddd),
{records1,another,[ddd,eee,fff], [ddd]} = hd(recon_rec:get_list()),
{records1,another,[ddd,eee,fff], ddd} = hd(recon_rec:get_list()),
recon_rec:limit(another, 3, [ddd, eee]),
{records1,another,[ddd,eee,fff], [ddd, eee]} = hd(recon_rec:get_list()),
recon_rec:limit(another, 3, all),
{records1,another,[ddd,eee,fff], all} = hd(recon_rec:get_list()),
recon_rec:clear(records2),
{error, record_unknown} = recon_rec:limit(another, 4, all),
{error, record_unknown} = recon_rec:limit(another, 4, none),
ok.

%%%%%%%%%% HELPERS

0 comments on commit 61a0aff

Please sign in to comment.