Class: ActionDispatch::Response::Buffer
- Inherits:
-
Object
- Object
- ActionDispatch::Response::Buffer
show all
- Defined in:
- lib/action_dispatch/http/response.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(response, buf) ⇒ Buffer
Returns a new instance of Buffer.
101
102
103
104
105
106
|
# File '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
#abort ⇒ Object
141
142
|
# File 'lib/action_dispatch/http/response.rb', line 141
def abort
end
|
#body ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/action_dispatch/http/response.rb', line 114
def body
@str_body ||= begin
buf = +""
each { |chunk| buf << chunk }
buf
end
end
|
#close ⇒ Object
144
145
146
147
|
# File 'lib/action_dispatch/http/response.rb', line 144
def close
@response.commit!
@closed = true
end
|
#closed? ⇒ Boolean
149
150
151
|
# File 'lib/action_dispatch/http/response.rb', line 149
def closed?
@closed
end
|
#each(&block) ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'lib/action_dispatch/http/response.rb', line 131
def each(&block)
if @str_body
return enum_for(:each) unless block_given?
yield @str_body
else
each_chunk(&block)
end
end
|
#to_ary ⇒ Object
108
109
110
111
112
|
# File 'lib/action_dispatch/http/response.rb', line 108
def to_ary
@buf.respond_to?(:to_ary) ?
@buf.to_ary :
@buf.each
end
|
#write(string) ⇒ Object
Also known as:
<<
122
123
124
125
126
127
128
|
# File 'lib/action_dispatch/http/response.rb', line 122
def write(string)
raise IOError, "closed stream" if closed?
@str_body = nil
@response.commit!
@buf.push string
end
|