Class: Vangrail::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/vangrail/reference_monitor.rb

Overview

Authorization result with a stable machine-readable reason.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#callObject (readonly)

Returns the value of attribute call.



106
107
108
# File 'lib/vangrail/reference_monitor.rb', line 106

def call
  @call
end

#grantObject (readonly)

Returns the value of attribute grant.



106
107
108
# File 'lib/vangrail/reference_monitor.rb', line 106

def grant
  @grant
end

#reasonObject (readonly)

Returns the value of attribute reason.



106
107
108
# File 'lib/vangrail/reference_monitor.rb', line 106

def reason
  @reason
end

#reason_codeObject (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

Returns:

  • (Boolean)


125
126
127
# File 'lib/vangrail/reference_monitor.rb', line 125

def allowed?
  @allowed
end

#denied?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/vangrail/reference_monitor.rb', line 129

def denied?
  !allowed?
end

#to_hObject



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