Class: ActionController::RackResponse

Inherits:
AbstractResponse show all
Defined in:
lib/action_controller/rack_process.rb

Overview

:nodoc:

Constant Summary

Constants inherited from AbstractResponse

AbstractResponse::DEFAULT_HEADERS

Instance Attribute Summary

Attributes inherited from AbstractResponse

#assigns, #body, #cookies, #headers, #layout, #redirected_to, #redirected_to_method_params, #request, #session, #template

Instance Method Summary collapse

Methods inherited from AbstractResponse

#assign_default_content_type_and_charset!, #charset, #charset=, #content_type, #content_type=, #etag, #etag=, #etag?, #last_modified, #last_modified=, #last_modified?, #location, #location=, #redirect, #sending_file?, #status=

Constructor Details

#initialize(request) ⇒ RackResponse

Returns a new instance of RackResponse.



156
157
158
159
160
161
# File 'lib/action_controller/rack_process.rb', line 156

def initialize(request)
  @cgi = request.cgi
  @writer = lambda { |x| @body << x }
  @block = nil
  super()
end

Instance Method Details

#closeObject



203
204
205
# File 'lib/action_controller/rack_process.rb', line 203

def close
  @body.close if @body.respond_to?(:close)
end

#each(&callback) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/action_controller/rack_process.rb', line 184

def each(&callback)
  if @body.respond_to?(:call)
    @writer = lambda { |x| callback.call(x) }
    @body.call(self, self)
  elsif @body.is_a?(String)
    @body.each_line(&callback)
  else
    @body.each(&callback)
  end

  @writer = callback
  @block.call(self) if @block
end

#empty?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/action_controller/rack_process.rb', line 207

def empty?
  @block == nil && @body.empty?
end

#out(output = $stdout, &block) ⇒ Object Also known as: to_a



168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/action_controller/rack_process.rb', line 168

def out(output = $stdout, &block)
  # Nasty hack because CGI sessions are closed after the normal
  # prepare! statement
  set_cookies!

  @block = block
  @status = headers.delete("Status")
  if [204, 304].include?(status.to_i)
    headers.delete("Content-Type")
    [status, headers.to_hash, []]
  else
    [status, headers.to_hash, self]
  end
end

#prepare!Object



211
212
213
214
215
216
217
218
# File 'lib/action_controller/rack_process.rb', line 211

def prepare!
  super

  convert_language!
  convert_expires!
  set_status!
  # set_cookies!
end

#statusObject

Retrieve status from instance variable if has already been delete



164
165
166
# File 'lib/action_controller/rack_process.rb', line 164

def status
  @status || super
end

#write(str) ⇒ Object



198
199
200
201
# File 'lib/action_controller/rack_process.rb', line 198

def write(str)
  @writer.call str.to_s
  str
end