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 101

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 149

def closed?
  @closed
end

Instance Method Details

#<<(string)

Alias for #write.

[ GitHub ]

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

alias_method :<<, :write

#abort

[ GitHub ]

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

def abort
end

#body

[ GitHub ]

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

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

#close

[ GitHub ]

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

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

#each(&block)

[ GitHub ]

  
# File 'actionpack/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

#each_chunk(&block) (private)

[ GitHub ]

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

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

#to_ary

[ GitHub ]

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

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 122

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

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