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.



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

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

Instance Method Details

#abortObject



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

def abort
end

#bodyObject



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

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

#closeObject



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

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

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  @closed
end

#each(&block) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'actionpack/lib/action_dispatch/http/response.rb', line 123

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

    yield @str_body
  else
    each_chunk(&block)
  end
end

#write(string) ⇒ Object

Raises:

  • (IOError)


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

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

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