Class: BetterAuth::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/better_auth/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, headers:, body:) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
# File 'lib/better_auth/response.rb', line 9

def initialize(status:, headers:, body:)
  @status = status
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/better_auth/response.rb', line 7

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/better_auth/response.rb', line 7

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/better_auth/response.rb', line 7

def status
  @status
end

Class Method Details

.from_rack(tuple) ⇒ Object



15
16
17
18
# File 'lib/better_auth/response.rb', line 15

def self.from_rack(tuple)
  status, headers, body = tuple
  new(status: status, headers: headers, body: body)
end

Instance Method Details

#[](index) ⇒ Object



30
31
32
# File 'lib/better_auth/response.rb', line 30

def [](index)
  to_a[index]
end

#each(&block) ⇒ Object



26
27
28
# File 'lib/better_auth/response.rb', line 26

def each(&block)
  to_a.each(&block)
end

#firstObject



34
35
36
# File 'lib/better_auth/response.rb', line 34

def first
  status
end

#json(**options) ⇒ Object



38
39
40
# File 'lib/better_auth/response.rb', line 38

def json(**options)
  JSON.parse(body.join, **options)
end

#to_aObject Also known as: to_ary



20
21
22
# File 'lib/better_auth/response.rb', line 20

def to_a
  [status, headers, body]
end