Class: Vangrail::Authorization
- Inherits:
-
Object
- Object
- Vangrail::Authorization
- Defined in:
- lib/vangrail/reference_monitor.rb
Overview
Authorization result with a stable machine-readable reason.
Instance Attribute Summary collapse
-
#call ⇒ Object
readonly
Returns the value of attribute call.
-
#grant ⇒ Object
readonly
Returns the value of attribute grant.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#reason_code ⇒ Object
readonly
Returns the value of attribute reason_code.
Class Method Summary collapse
Instance Method Summary collapse
- #allowed? ⇒ Boolean
- #denied? ⇒ Boolean
-
#initialize(call:, allowed:, grant: nil, reason_code: nil, reason: nil) ⇒ Authorization
constructor
A new instance of Authorization.
- #to_h ⇒ Object
Constructor Details
#initialize(call:, allowed:, grant: nil, reason_code: nil, reason: nil) ⇒ Authorization
Returns a new instance of Authorization.
108 109 110 111 112 113 114 115 |
# File 'lib/vangrail/reference_monitor.rb', line 108 def initialize(call:, allowed:, grant: nil, reason_code: nil, reason: nil) @call = call @allowed = allowed @grant = grant @reason_code = reason_code&.to_sym @reason = reason freeze end |
Instance Attribute Details
#call ⇒ Object (readonly)
Returns the value of attribute call.
106 107 108 |
# File 'lib/vangrail/reference_monitor.rb', line 106 def call @call end |
#grant ⇒ Object (readonly)
Returns the value of attribute grant.
106 107 108 |
# File 'lib/vangrail/reference_monitor.rb', line 106 def grant @grant end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
106 107 108 |
# File 'lib/vangrail/reference_monitor.rb', line 106 def reason @reason end |
#reason_code ⇒ Object (readonly)
Returns the value of attribute reason_code.
106 107 108 |
# File 'lib/vangrail/reference_monitor.rb', line 106 def reason_code @reason_code end |
Class Method Details
.allow(call, grant) ⇒ Object
117 118 119 |
# File 'lib/vangrail/reference_monitor.rb', line 117 def self.allow(call, grant) new(call: call, allowed: true, grant: grant) end |
.deny(call, reason_code, reason) ⇒ Object
121 122 123 |
# File 'lib/vangrail/reference_monitor.rb', line 121 def self.deny(call, reason_code, reason) new(call: call, allowed: false, reason_code: reason_code, reason: reason) end |
Instance Method Details
#allowed? ⇒ Boolean
125 126 127 |
# File 'lib/vangrail/reference_monitor.rb', line 125 def allowed? @allowed end |
#denied? ⇒ Boolean
129 130 131 |
# File 'lib/vangrail/reference_monitor.rb', line 129 def denied? !allowed? end |
#to_h ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/vangrail/reference_monitor.rb', line 133 def to_h { 'allowed' => allowed?, 'call_id' => call.id, 'grant_id' => grant&.id, 'reason_code' => reason_code&.to_s, 'reason' => reason, }.compact end |