Class: ActionDispatch::Response::Buffer

Inherits:
Object
  • Object
show all
Defined in:
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.



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

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

Instance Method Details

#abortObject



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

def abort
end

#bodyObject



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

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

#closeObject



147
148
149
150
# File 'lib/action_dispatch/http/response.rb', line 147

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

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  @closed
end

#each(&block) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/action_dispatch/http/response.rb', line 134

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)


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

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

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