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.



150
151
152
153
154
155
# File 'lib/action_controller/rack_process.rb', line 150

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

Instance Method Details

#closeObject



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

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

#each(&callback) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/action_controller/rack_process.rb', line 178

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)


201
202
203
# File 'lib/action_controller/rack_process.rb', line 201

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

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



162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/action_controller/rack_process.rb', line 162

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



205
206
207
208
209
210
211
212
# File 'lib/action_controller/rack_process.rb', line 205

def prepare!
  super

  convert_language!
  convert_expires!
  set_status!
  # set_cookies!
end

#statusObject

Retrieve status from instance variable if has already been delete



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

def status
  @status || super
end

#write(str) ⇒ Object



192
193
194
195
# File 'lib/action_controller/rack_process.rb', line 192

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