Class: ActionDispatch::Response::Buffer

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/http/response.rb

Overview

:nodoc:

Direct Known Subclasses

ActionController::Live::Buffer

Instance Method Summary collapse

Constructor Details

#initialize(response, buf) ⇒ Buffer

Returns a new instance of Buffer.



98
99
100
101
102
103
# File 'actionpack/lib/action_dispatch/http/response.rb', line 98

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

Instance Method Details

#abortObject



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

def abort
end

#bodyObject



109
110
111
112
113
114
115
# File 'actionpack/lib/action_dispatch/http/response.rb', line 109

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

#closeObject



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

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

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  @closed
end

#each(&block) ⇒ Object



126
127
128
129
130
131
132
133
134
# File 'actionpack/lib/action_dispatch/http/response.rb', line 126

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

    yield @str_body
  else
    each_chunk(&block)
  end
end

#to_aryObject



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

def to_ary
  @buf.to_ary
end

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

Raises:

  • (IOError)


117
118
119
120
121
122
123
# File 'actionpack/lib/action_dispatch/http/response.rb', line 117

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

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