Class: IORequest::Authorizer
- Inherits:
-
Object
- Object
- IORequest::Authorizer
- Defined in:
- lib/io_request/authorizer.rb
Overview
Class to authorize client connection.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Literally any non-nil data from block.
Class Method Summary collapse
-
.by_secret_key(key) ⇒ Object
Secret key authorization.
-
.empty ⇒ Object
No authorization.
Instance Method Summary collapse
-
#authorize(io_r, io_w) ⇒ Boolean
Authorization status.
-
#initialize {|io_r, io_w| ... } ⇒ Authorizer
constructor
A new instance of Authorizer.
Constructor Details
#initialize {|io_r, io_w| ... } ⇒ Authorizer
Returns a new instance of Authorizer.
10 11 12 13 |
# File 'lib/io_request/authorizer.rb', line 10 def initialize(&block) @block = block @data = nil end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns literally any non-nil data from block.
16 17 18 |
# File 'lib/io_request/authorizer.rb', line 16 def data @data end |
Class Method Details
.by_secret_key(key) ⇒ Object
Secret key authorization.
35 36 37 38 39 40 41 |
# File 'lib/io_request/authorizer.rb', line 35 def Authorizer.by_secret_key(key) Authorizer.new do |io_r, io_w| io_w.write(key) other = io_r.read(key.size) key == other ? other : nil end end |
.empty ⇒ Object
No authorization.
30 31 32 |
# File 'lib/io_request/authorizer.rb', line 30 def Authorizer.empty Authorizer.new { |_io_r, _io_w| true } end |