Class: Faraday::Adapter::NetHttpStream::BodyStream

Inherits:
Object
  • Object
show all
Defined in:
lib/tent-client/faraday/chunked_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(env, &stream_body) ⇒ BodyStream

Returns a new instance of BodyStream.



9
10
11
12
# File 'lib/tent-client/faraday/chunked_adapter.rb', line 9

def initialize(env, &stream_body)
  @env, @stream_body = env, stream_body
  @read_body = false
end

Instance Method Details

#each(&block) ⇒ Object



14
15
16
17
18
# File 'lib/tent-client/faraday/chunked_adapter.rb', line 14

def each(&block)
  return if @read_body
  @stream_body.call(block)
  @read_body = true
end

#readObject



20
21
22
23
24
25
26
27
# File 'lib/tent-client/faraday/chunked_adapter.rb', line 20

def read
  return @body if @body
  @body = ""
  each do |chunk|
    @body << chunk
  end
  @body
end