Browse Source

Update README and add additional tests

develop-0.1.9
Pedram Nimreezi 9 years ago
parent
commit
58f74af809
3 changed files with 43 additions and 2 deletions
  1. +7
    -2
      README.org
  2. +35
    -0
      src/glc_lib.erl
  3. +1
    -0
      src/glc_ops.erl

+ 7
- 2
README.org View File

@ -221,13 +221,14 @@ Return the stored value in this query module.
* Job processing with composed modules
- You can use query modules to execute jobs, if the job doesn't error, process an event.
- You can use query modules to execute jobs, if the job errors or not, process an event.
- `with' is similar to `run', the main difference is additional statistics and execution order
- when a job completes in error, the event data will contain an additional {error, _} item
To execute a job through the query module, inputting an event on success.
#+BEGIN_EXAMPLE
Event = gre:make([{'a', 2}], [list]).
Result = glc:run(Module, fun(Event, State) ->
{ExecutionTime, Result}= glc:run(Module, fun(Event, State) ->
%% do not end with {error, _} or throw an exception
end, Event).
#+END_EXAMPLE
@ -287,6 +288,10 @@ Return the query combining the conditional logic of multiple modules
glc_lib:reduce(glc:all([Module1:info('query'), Module2:info('query')]).
#+END_EXAMPLE
Return all statistics from this query module.
#+BEGIN_EXAMPLE
glc:info(Module).
#+END_EXAMPLE
* Build

+ 35
- 0
src/glc_lib.erl View File

@ -60,6 +60,11 @@ matches({Key, '<', Term}, Event) ->
{true, Term2} -> Term2 < Term;
false -> false
end;
matches({Key, '=<', Term}, Event) ->
case gre:find(Key, Event) of
{true, Term2} -> Term2 =< Term;
false -> false
end;
matches({Key, '=', Term}, Event) ->
case gre:find(Key, Event) of
{true, Term2} -> Term2 =:= Term;
@ -75,6 +80,11 @@ matches({Key, '>', Term}, Event) ->
{true, Term2} -> Term2 > Term;
false -> false
end;
matches({Key, '>=', Term}, Event) ->
case gre:find(Key, Event) of
{true, Term2} -> Term2 >= Term;
false -> false
end;
matches({Key, '*'}, Event) ->
case gre:find(Key, Event) of
{true, _} -> true;
@ -97,10 +107,14 @@ repeat(Query, Fun) ->
-spec onoutput(glc_ops:op()) -> output | no_return().
onoutput({_, '<', _}) ->
output;
onoutput({_, '=<', _}) ->
output;
onoutput({_, '=', _}) ->
output;
onoutput({_, '>', _}) ->
output;
onoutput({_, '>=', _}) ->
output;
onoutput({_, '*'}) ->
output;
onoutput({_, '!'}) ->
@ -382,12 +396,33 @@ delete_from_any_test() ->
default_is_output_test_() ->
[?_assertEqual(output, glc_lib:onoutput(glc:lt(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:lte(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:eq(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:gt(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:gte(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:wc(a))),
?_assertEqual(output, glc_lib:onoutput(glc:nf(a)))
].
matches_test_() ->
Event = gre:make([{a, 2}], [list]),
[?_assertEqual(true, glc_lib:matches(glc:lt(a, 3), Event)),
?_assertEqual(true, glc_lib:matches(glc:lte(a, 2), Event)),
?_assertEqual(true, glc_lib:matches(glc:eq(a, 2), Event)),
?_assertEqual(true, glc_lib:matches(glc:gt(a, 1), Event)),
?_assertEqual(true, glc_lib:matches(glc:gte(a, 2), Event)),
?_assertEqual(true, glc_lib:matches(glc:wc(a), Event)),
?_assertEqual(true, glc_lib:matches(glc:nf(b), Event)),
?_assertEqual(false, glc_lib:matches(glc:lt(a, 2), Event)),
?_assertEqual(false, glc_lib:matches(glc:lte(a, 1), Event)),
?_assertEqual(false, glc_lib:matches(glc:eq(a, 3), Event)),
?_assertEqual(false, glc_lib:matches(glc:gt(a, 2), Event)),
?_assertEqual(false, glc_lib:matches(glc:gte(a, 3), Event)),
?_assertEqual(false, glc_lib:matches(glc:wc(b), Event)),
?_assertEqual(false, glc_lib:matches(glc:nf(a), Event))
].
-ifdef(PROPER).

+ 1
- 0
src/glc_ops.erl View File

@ -21,6 +21,7 @@
]).
-type op() ::
{atom(), '<', term()} |
{atom(), '=<', term()} |
{atom(), '=', term()} |
{atom(), '!=', term()} |

Loading…
Cancel
Save