Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
manfred-kaiser committed Nov 2, 2021
2 parents 29551fe + 4477fd4 commit 336aff9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.2.0] - 2021-11-02

### Added

- added add_rule method to RuleParser


## [0.1.3] - 2021-06-15

### Fixed
Expand Down Expand Up @@ -74,6 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Initial release


[0.2.0]: https://github.com/manfred-kaiser/business-rule-engine/compare/0.1.3...0.2.0
[0.1.3]: https://github.com/manfred-kaiser/business-rule-engine/compare/0.1.2...0.1.3
[0.1.2]: https://github.com/manfred-kaiser/business-rule-engine/compare/0.1.1...0.1.2
[0.1.1]: https://github.com/manfred-kaiser/business-rule-engine/compare/0.1.0...0.1.1
Expand Down
8 changes: 8 additions & 0 deletions business_rule_engine/__init__.py
Expand Up @@ -122,6 +122,14 @@ def parsestr(self, text: Text) -> None:
if rulename and is_action and not ignore_line:
self.rules[rulename].actions.append(line.strip())

def add_rule(self, rulename: Text, condition: Text, action: Text) -> None:
if rulename in self.rules:
raise DuplicateRuleName("Rule '{}' already exists!".format(rulename))
rule = Rule(rulename)
rule.conditions.append(condition)
rule.actions.append(action)
self.rules[rulename] = rule

@classmethod
def register_function(cls, function: Any, function_name: Optional[Text] = None) -> None:
custom_function_name = function_name or function.__name__
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -10,7 +10,7 @@

setup(
name='business-rule-engine',
version='0.1.3',
version='0.2.0',
author='Manfred Kaiser',
author_email='manfred.kaiser@logfile.at',
description='Python DSL for setting up business intelligence rules',
Expand Down
9 changes: 9 additions & 0 deletions tests/test_rules.py
Expand Up @@ -94,3 +94,12 @@ def test_rule():

assert rule.check_condition(params) == True
assert rule.run_action(params) == 5


def test_add_rule():
parser = RuleParser()
parser.add_rule('testrule', 'products_in_stock < 20', '2 + 3')
params = {
'products_in_stock': 10
}
parser.execute(params)

0 comments on commit 336aff9

Please sign in to comment.