apply and list patterns in alphabetical orders; added functions to manage entries
diff --git a/src/recon_map.erl b/src/recon_map.erl
index 10bc4d8..d1ee616 100644
--- a/src/recon_map.erl
+++ b/src/recon_map.erl
@@ -18,6 +18,7 @@
-export([process_map/1]).
-export([is_active/0]).
-export([clear/0]).
+-export([remove/1, rename/2]).
-type map_label() :: atom().
-type pattern() :: map().
@@ -42,6 +43,8 @@
%% are present in a map (in other words, the pattern is a subset), then we say the map matches
%% and we process it accordingly (apply the limit).
%%
+%% Patterns are applied in alphabetical order, until a match is found.
+%%
%% Instead of a pattern you can also provide a function which will take a map and return a boolean.
%% @end
-spec limit(map_label(), pattern(), limit()) -> ok | {error, any()}.
@@ -55,6 +58,21 @@
io:format("~nmap definitions and limits:~n"),
list(lists:sort(ets:tab2list(patterns_table_name()))).
+remove(Label) ->
+ ensure_table_exists(),
+ ets:delete(patterns_table_name(), Label).
+
+rename(Name, NewName) ->
+ ensure_table_exists(),
+ case ets:lookup(patterns_table_name(), Name) of
+ [{Name, Pattern, Limit}] ->
+ ets:delete(patterns_table_name(), Name),
+ ets:insert(patterns_table_name(), {NewName, Pattern, Limit}),
+ renamed;
+ [] ->
+ missing
+ end.
+
list([]) ->
io:format("~n"),
ok;
@@ -124,7 +142,7 @@
%% attach to the currently running session
{Pid, MonRef} = spawn_monitor(fun() ->
register(recon_ets_maps, self()),
- ets:new(patterns_table_name(), [set, public, named_table]),
+ ets:new(patterns_table_name(), [ordered_set, public, named_table]),
Parent ! Ref,
ets_keeper()
end),