Class: ActionDispatch::Response::Buffer
- Inherits:
-
Object
- Object
- ActionDispatch::Response::Buffer
show all
- Defined in:
- lib/action_dispatch/http/response.rb
Overview
Constant Summary
collapse
- BODY_METHODS =
{ to_ary: true }
Instance Method Summary
collapse
Constructor Details
#initialize(response, buf) ⇒ Buffer
Returns a new instance of Buffer.
115
116
117
118
119
120
|
# File 'lib/action_dispatch/http/response.rb', line 115
def initialize(response, buf)
@response = response
@buf = buf
@closed = false
@str_body = nil
end
|
Instance Method Details
#abort ⇒ Object
167
168
|
# File 'lib/action_dispatch/http/response.rb', line 167
def abort
end
|
#body ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/action_dispatch/http/response.rb', line 140
def body
@str_body ||= begin
buf = +""
each { |chunk| buf << chunk }
buf
end
end
|
#close ⇒ Object
170
171
172
173
|
# File 'lib/action_dispatch/http/response.rb', line 170
def close
@response.commit!
@closed = true
end
|
#closed? ⇒ Boolean
175
176
177
|
# File 'lib/action_dispatch/http/response.rb', line 175
def closed?
@closed
end
|
#each(&block) ⇒ Object
157
158
159
160
161
162
163
164
165
|
# File 'lib/action_dispatch/http/response.rb', line 157
def each(&block)
if @str_body
return enum_for(:each) unless block_given?
yield @str_body
else
each_chunk(&block)
end
end
|
#respond_to?(method, include_private = false) ⇒ Boolean
124
125
126
127
128
129
130
|
# File 'lib/action_dispatch/http/response.rb', line 124
def respond_to?(method, include_private = false)
if BODY_METHODS.key?(method)
@buf.respond_to?(method)
else
super
end
end
|
#to_ary ⇒ Object
132
133
134
135
136
137
138
|
# File 'lib/action_dispatch/http/response.rb', line 132
def to_ary
if @str_body
[body]
else
@buf = @buf.to_ary
end
end
|
#write(string) ⇒ Object
Also known as:
<<
148
149
150
151
152
153
154
|
# File 'lib/action_dispatch/http/response.rb', line 148
def write(string)
raise IOError, "closed stream" if closed?
@str_body = nil
@response.commit!
@buf.push string
end
|