123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Response::Buffer

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: actionpack/lib/action_dispatch/http/response.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(response, buf) ⇒ Buffer

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 99

def initialize(response, buf)
  @response = response
  @buf      = buf
  @closed   = false
  @str_body = nil
end

Instance Attribute Details

#closed?Boolean (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 147

def closed?
  @closed
end

Instance Method Details

#<<(string)

Alias for #write.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 127

alias_method :<<, :write

#abort

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 139

def abort
end

#body

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 112

def body
  @str_body ||= begin
    buf = +""
    each { |chunk| buf << chunk }
    buf
  end
end

#close

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 142

def close
  @response.commit!
  @closed = true
end

#each(&block)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 129

def each(&block)
  if @str_body
    return enum_for(:each) unless block_given?

    yield @str_body
  else
    each_chunk(&block)
  end
end

#each_chunk(&block) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 152

def each_chunk(&block)
  @buf.each(&block)
end

#to_ary

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 106

def to_ary
  @buf.respond_to?(:to_ary) ?
    @buf.to_ary :
    @buf.each
end

#write(string) Also known as: #<<

Raises:

  • (IOError)
[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/http/response.rb', line 120

def write(string)
  raise IOError, "closed stream" if closed?

  @str_body = nil
  @response.commit!
  @buf.push string
end