An enterprise rules engine for all your needs
Uses the Boolean DSL gem for handling logic
Add this line to your application's Gemfile:
gem 'rules_engine'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rules_engine
Single outcome:
true_outcome = RulesEngine::Outcome.new(name: "Outcome 1", values: "Outcome 1 Values")
false_outcome = RulesEngine::Outcome.new(name: "Outcome 2", values: "Outcome 2 Values")
root = RulesEngine::Condition.new(name: "Root", condition: "2 > 1", when_true: true_outcome, when_false: false_outcome)
set = RulesEngine::Set.new(name: "Single Outcome", root: root)
walker = RulesEngine::Walker.new(set: set, event_logger: nil)
walker.walk
# Executing Rule Set Single Outcome
# Evaluated condition 2 > 1, result is true (overridden: false)
# => #<RulesEngine::Outcome:... @name="Outcome 1", @values="Outcome 1 Values">
Multiple outcomes:
outcome_1 = RulesEngine::Outcome.new(name: "Outcome 1", values: "Outcome 1 Values")
outcome_2 = RulesEngine::Outcome.new(name: "Outcome 2", values: "Outcome 2 Values")
outcome_3 = RulesEngine::Outcome.new(name: "Outcome 3", values: "Outcome 3 Values")
outcome_4 = RulesEngine::Outcome.new(name: "Outcome 4", values: "Outcome 4 Values")
condition_1 = RulesEngine::Condition.new(name: "Condition 1", condition: "2 < 1", when_true_outcome: outcome_3, when_false_outcome: outcome_4)
root = RulesEngine::Condition.new(name: "Root", condition: "2 > 1", when_true_outcome: outcome_1, when_true_condition: condition_1, when_false_outcome: outcome_2, when_false_condition: condition_1)
set = RulesEngine::Set.new(name: "Multiple Outcomes", root: root, multiple_outcomes: true)
walker = RulesEngine::Walker.new(set: set, event_logger: nil)
walker.walk
# Executing Rule Set Multiple Outcomes
# Evaluated condition 2 > 1, result is true (overridden: false)
# Evaluated condition 2 < 1, result is false (overridden: false)
# => [#<RulesEngine::Outcome:... @name="Outcome 1", @values="Outcome 1 Values">,
#<RulesEngine::Outcome:... @name="Outcome 4", @values="Outcome 4 Values">]
- Fork it ( http://github.com/jobready/rules_engine )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request