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

Constant Summary

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 161

def closed?
  @closed
end

Instance Method Details

#<<(string)

Alias for #write.

[ GitHub ]

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

alias_method :<<, :write

#abort

[ GitHub ]

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

def abort
end

#body

[ GitHub ]

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

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

#close

[ GitHub ]

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

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

#each(&block)

[ GitHub ]

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

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 166

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

#respond_to?(method, include_private = false) ⇒ Boolean

[ GitHub ]

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

def respond_to?(method, include_private = false)
  if BODY_METHODS.key?(method)
    @buf.respond_to?(method)
  else
    super
  end
end

#to_ary

[ GitHub ]

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

def to_ary
  if @str_body
    [body]
  else
    @buf = @buf.to_ary
  end
end

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

Raises:

  • (IOError)
[ GitHub ]

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

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

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