Class: Legion::Extensions::React::RuleEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::React::RuleEngine
- Defined in:
- lib/legion/extensions/react/rule_engine.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(rules_hash = {}) ⇒ RuleEngine
constructor
A new instance of RuleEngine.
- #match(event) ⇒ Object
Constructor Details
#initialize(rules_hash = {}) ⇒ RuleEngine
Returns a new instance of RuleEngine.
9 10 11 |
# File 'lib/legion/extensions/react/rule_engine.rb', line 9 def initialize(rules_hash = {}) @rules = parse_rules(rules_hash) end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
7 8 9 |
# File 'lib/legion/extensions/react/rule_engine.rb', line 7 def rules @rules end |
Class Method Details
.from_settings ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/react/rule_engine.rb', line 13 def self.from_settings rules_hash = if defined?(Legion::Settings) && !Legion::Settings[:react].nil? Legion::Settings.dig(:react, :rules) || {} else {} end new(rules_hash) rescue StandardError new({}) end |
Instance Method Details
#match(event) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/legion/extensions/react/rule_engine.rb', line 24 def match(event) event_name = event[:event].to_s @rules.select do |rule| Helpers::EventMatcher.match?(rule[:source], event_name) && Helpers::EventMatcher.evaluate_condition(rule[:condition], event) end end |