Permalink
Browse files

Added 'aint' rule, offers negation.

The 'aint' rule allows you to specify the negation of a rule, if that
rule returns ok or error, at least. Example:

   check_rule(<<"a">>, {aint, {in, [<<"b">>]}}) => ok

This is useful if you have a property that must be false.

Signed-off-by: Brian L. Troutwine <brian.troutwine@rackspace.com>
  • Loading branch information...
1 parent 38d8999 commit d570250274ce5a9155ff97d5a95d76ba11cbb8e0 Brian L. Troutwine committed Apr 16, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/deputy.erl
View
@@ -191,6 +191,13 @@ check_proplist([{Key, Value} | Values], [{Key, Rules0} | Rules], Results, Errors
%% @private
%% @doc Check built in rules.
+check_rule(Value, {aint, Rule}) ->
+ case check_rule(Value, Rule) of
+ error ->
+ ok;
+ ok ->
+ error
+ end;
check_rule(Value, {convert, Type}) when is_atom(Type) ->
case convert(Value, Type) of
error ->
@@ -329,6 +336,11 @@ rule_regexp_test_() ->
[?_assertEqual(ok, check_rule(<<"a">>, {regexp, <<"^a">>})),
?_assertEqual(error, check_rule(<<"b">>, {regexp, <<"^a">>}))].
+rule_aint_test_() ->
+ [?_assertEqual(error, check_rule(<<"a">>, {aint, {in, [<<"a">>, <<"b">>]}}) ),
+ ?_assertEqual(ok, check_rule(<<"b">>, {aint, {in, [<<"a">>, <<"c">>]}}) )
+ ].
+
rule_in_test_() ->
[?_assertEqual(ok, check_rule(<<"a">>, {in, [<<"a">>, <<"b">>]})),
?_assertEqual(error, check_rule(<<"b">>, {in, [<<"a">>, <<"c">>]}))].

0 comments on commit d570250

Please sign in to comment.