From 18be4c2e9eb06e30411794372c2fbde0d901da39 Mon Sep 17 00:00:00 2001 From: Ahmed Nafies Date: Fri, 2 Feb 2024 17:48:49 +0100 Subject: [PATCH] docs: fixes with new result field --- docs/all.md | 2 +- docs/any.md | 4 ++-- docs/index.md | 2 +- docs/not.md | 4 ++-- docs/run_vs_run_all.md | 5 ++--- docs/when_then.md | 8 +++++--- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/all.md b/docs/all.md index 232a2f9..eb7b063 100644 --- a/docs/all.md +++ b/docs/all.md @@ -20,5 +20,5 @@ obj = [1,2] RulesEngine(Rule(all_(not_(is_missing), is_a_list), then(True))).run(obj) ->>> True +>>> Result(value=True, message=None) ``` diff --git a/docs/any.md b/docs/any.md index ead1c40..1eba4f5 100644 --- a/docs/any.md +++ b/docs/any.md @@ -18,7 +18,7 @@ def is_a_list(obj): obj = "Hello" -RulesEngine(Rule(any_(is_a_str, is_a_list), then(True))).run(obj) +RulesEngine(Rule(any_(is_a_str, is_a_list), then(True), "it is a string or a list")).run(obj) ->>> True +>>> Result(value=True, message="it is a string or a list") ``` diff --git a/docs/index.md b/docs/index.md index 9f3a00e..3238540 100644 --- a/docs/index.md +++ b/docs/index.md @@ -29,6 +29,6 @@ name = "fyndiq" RulesEngine(Rule(when(name == "fyndiq"),then(True))).run(name) ->> True +>>> Result(value=True, message='it is fyndiq') ``` diff --git a/docs/not.md b/docs/not.md index 2fb82c3..4188eef 100644 --- a/docs/not.md +++ b/docs/not.md @@ -14,7 +14,7 @@ def is_missing(obj): obj="Hello" -RulesEngine(Rule(not_(is_missing), then(True))).run(obj) +RulesEngine(Rule(not_(is_missing), then(True)), 'object is missing').run(obj) ->>> True +>>> Result(value=True, message='object is missing') ``` diff --git a/docs/run_vs_run_all.md b/docs/run_vs_run_all.md index 1d0af5d..09de16e 100644 --- a/docs/run_vs_run_all.md +++ b/docs/run_vs_run_all.md @@ -23,7 +23,7 @@ RulesEngine( Rule(is_string, then("string")), ).run(value) ->>> "integer" +>>> Result(value='integer', message=None) ``` Since the first rule satisfies the conditions the rules engine will go no further @@ -46,7 +46,6 @@ def is_gr_3_chars(value): return len(value) > 3 - value="Hello" RulesEngine( Rule(is_integer, then("integer")), @@ -54,6 +53,6 @@ RulesEngine( Rule(is_gr_3_chars, then("greater than 3 charcters")), ).run_all(value) ->>> ["string", "greater than 3 charcters"] +>>>[Result(value='string', message=None),Result(value='greater than 3 charcters', message=None)] ``` diff --git a/docs/when_then.md b/docs/when_then.md index 86aad46..8d13110 100644 --- a/docs/when_then.md +++ b/docs/when_then.md @@ -11,12 +11,13 @@ let's check if a value is `None` and raise an exception. from rules_engine import Rule, RulesEngine, when obj = None -def cannot_be_none_error(): +def no_a_string(obj): return "not a string error" RulesEngine(Rule(when(obj is None), cannot_be_none_error)).run(obj) ->>> 'not a string error' +>>> Result(value='not a string error', message=None)>> 'not a string error' + ``` ## Then @@ -30,5 +31,6 @@ obj = None RulesEngine(Rule(when(obj is None), then('not a string error'))).run(obj) ->>> 'not a string error' +>>> Result(value='not a string error', message=None) + ```