Class: ReactOnRailsPro::RendererHttpClient::Response
- Inherits:
-
Object
- Object
- ReactOnRailsPro::RendererHttpClient::Response
- Defined in:
- lib/react_on_rails_pro/renderer_http_client.rb
Overview
Not thread-safe. Each Response instance is owned and consumed by one renderer request path.
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #body ⇒ Object
- #each(&block) ⇒ Object
- #error? ⇒ Boolean
-
#initialize(status: nil, body: nil, error: nil, &executor) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(status: nil, body: nil, error: nil, &executor) ⇒ Response
Returns a new instance of Response.
97 98 99 100 101 102 103 104 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 97 def initialize(status: nil, body: nil, error: nil, &executor) @status = status @body_chunks = Array(body || []) @body = nil @error = error @executor = executor @consumed = false end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
95 96 97 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 95 def status @status end |
Instance Method Details
#body ⇒ Object
106 107 108 109 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 106 def body consume unless @consumed @body ||= @body_chunks.join end |
#each(&block) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 116 def each(&block) return enum_for(:each) unless block if @executor && !@consumed consume(&block) else @body_chunks.each(&block) end # Replaying consumed chunks should still surface the stored response failure. raise @error if @error raise HTTPError, self if error? end |
#error? ⇒ Boolean
111 112 113 114 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 111 def error? # nil status means a lazy streaming executor has not run yet, so it is not-yet-an-error. !status.nil? && status >= 400 end |