Skip to content

Commit

Permalink
docs: fixes with new result field
Browse files Browse the repository at this point in the history
  • Loading branch information
nf1s committed Feb 2, 2024
1 parent 577186c commit 18be4c2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
4 changes: 2 additions & 2 deletions docs/any.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ name = "fyndiq"

RulesEngine(Rule(when(name == "fyndiq"),then(True))).run(name)

>> True
>>> Result(value=True, message='it is fyndiq')

```
4 changes: 2 additions & 2 deletions docs/not.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
```
5 changes: 2 additions & 3 deletions docs/run_vs_run_all.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,14 +46,13 @@ def is_gr_3_chars(value):
return len(value) > 3



value="Hello"
RulesEngine(
Rule(is_integer, then("integer")),
Rule(is_string, then("string")),
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)]

```
8 changes: 5 additions & 3 deletions docs/when_then.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

```

0 comments on commit 18be4c2

Please sign in to comment.