Module: Liteguard::Evaluation

Defined in:
lib/liteguard/evaluation.rb

Overview

Local rule evaluation engine. All evaluation is done without network calls.

Class Method Summary collapse

Class Method Details

.evaluate_guard(guard, properties) ⇒ Boolean

Evaluate a guard against a property hash.

Rules are processed in order and the first matching rule determines the result. If no enabled rule matches, the guard’s configured default value is returned.

Parameters:

  • guard (Guard)

    guard definition to evaluate

  • properties (Hash{String => Object})

    normalized evaluation properties

Returns:

  • (Boolean)

    the resolved open/closed result



13
14
15
16
17
18
19
# File 'lib/liteguard/evaluation.rb', line 13

def self.evaluate_guard(guard, properties)
  guard.rules.each do |rule|
    next unless rule.enabled
    return rule.result if matches_rule?(rule, properties)
  end
  guard.default_value
end

.evaluate_guard_detailed(guard, properties) ⇒ DetailedEvalResult

Evaluate a guard and return both the result and the matched rule index.

Parameters:

  • guard (Guard)

    guard definition to evaluate

  • properties (Hash{String => Object})

    normalized evaluation properties

Returns:



26
27
28
29
30
31
32
33
34
# File 'lib/liteguard/evaluation.rb', line 26

def self.evaluate_guard_detailed(guard, properties)
  guard.rules.each_with_index do |rule, i|
    next unless rule.enabled
    if matches_rule?(rule, properties)
      return DetailedEvalResult.new(result: rule.result, matched_rule_index: i)
    end
  end
  DetailedEvalResult.new(result: guard.default_value, matched_rule_index: -1)
end