Class: Preverus::DecisionResult

Inherits:
ApiResult show all
Defined in:
lib/preverus/results.rb

Instance Attribute Summary collapse

Attributes inherited from ApiResult

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiResult

#[], #to_h

Constructor Details

#initialize(data, fallback: false, failure_reason: nil) ⇒ DecisionResult

Returns a new instance of DecisionResult.



21
22
23
24
25
# File 'lib/preverus/results.rb', line 21

def initialize(data, fallback: false, failure_reason: nil)
  super(data)
  @fallback = fallback
  @failure_reason = failure_reason
end

Instance Attribute Details

#failure_reasonObject (readonly)

Returns the value of attribute failure_reason.



19
20
21
# File 'lib/preverus/results.rb', line 19

def failure_reason
  @failure_reason
end

Class Method Details

.fallback(action, reason) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/preverus/results.rb', line 27

def self.fallback(action, reason)
  new(
    {
      "recommended_action" => action,
      "risk_tier" => action == "allow" ? "unknown" : "review",
      "reasons" => [
        {
          "code" => "preverus_unavailable",
          "severity" => action == "allow" ? "low" : "medium",
          "message" => "Preverus was unavailable; fallback policy was applied."
        }
      ]
    },
    fallback: true,
    failure_reason: reason
  )
end

Instance Method Details

#allow?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/preverus/results.rb', line 49

def allow?
  recommended_action == "allow"
end

#block?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/preverus/results.rb', line 57

def block?
  ["block", "deny"].include?(recommended_action)
end

#fallback?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/preverus/results.rb', line 61

def fallback?
  @fallback
end


45
46
47
# File 'lib/preverus/results.rb', line 45

def recommended_action
  self["recommended_action"] || self["action"] || "review"
end

#review?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/preverus/results.rb', line 53

def review?
  recommended_action == "review"
end