Class: ActionDispatch::Response::Buffer
- Inherits:
-
Object
- Object
- ActionDispatch::Response::Buffer
show all
- Defined in:
- actionpack/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.
101
102
103
104
105
106
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 101
def initialize(response, buf)
@response = response
@buf = buf
@closed = false
@str_body = nil
end
|
Instance Method Details
153
154
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 153
def abort
end
|
126
127
128
129
130
131
132
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 126
def body
@str_body ||= begin
buf = +""
each { |chunk| buf << chunk }
buf
end
end
|
156
157
158
159
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 156
def close
@response.commit!
@closed = true
end
|
#closed? ⇒ Boolean
161
162
163
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 161
def closed?
@closed
end
|
#each(&block) ⇒ Object
143
144
145
146
147
148
149
150
151
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 143
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
110
111
112
113
114
115
116
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 110
def respond_to?(method, include_private = false)
if BODY_METHODS.key?(method)
@buf.respond_to?(method)
else
super
end
end
|
118
119
120
121
122
123
124
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 118
def to_ary
if @str_body
[body]
else
@buf = @buf.to_ary
end
end
|
#write(string) ⇒ Object
Also known as:
<<
134
135
136
137
138
139
140
|
# File 'actionpack/lib/action_dispatch/http/response.rb', line 134
def write(string)
raise IOError, "closed stream" if closed?
@str_body = nil
@response.commit!
@buf.push string
end
|