Class: Rack::Idempotency::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, headers, body) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
# File 'lib/rack/idempotency/response.rb', line 8

def initialize(status, headers, body)
  @status  = status.to_i
  @headers = Rack::Utils::HeaderHash.new(headers)
  @body    = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/rack/idempotency/response.rb', line 6

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/rack/idempotency/response.rb', line 6

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/rack/idempotency/response.rb', line 6

def status
  @status
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rack/idempotency/response.rb', line 14

def success?
  status.to_i >= 200 && status.to_i < 400
end

#to_aObject



18
19
20
# File 'lib/rack/idempotency/response.rb', line 18

def to_a
  [status, headers.to_hash, body.each(&:to_s)]
end

#to_jsonObject



22
23
24
# File 'lib/rack/idempotency/response.rb', line 22

def to_json
  to_a.to_json
end