Sha256: 79a09a6c1cca2b01e27f718d3aaa4e17284411b07c7e33dfe3a925fc315f7e3e

Contents?: true

Size: 885 Bytes

Versions: 2

Compression:

Stored size: 885 Bytes

Contents

module Webmachine
  module Adapters
    # Wraps a request body so that it can be passed to
    # {Request} while still lazily evaluating the body.
    class LazyRequestBody
      def initialize(request)
        @request = request
      end

      # Converts the body to a String so you can work with the entire
      # thing.
      def to_s
        @request.body
      end

      # Converts the body to a String and checks if it is empty.
      def empty?
        to_s.empty?
      end

      # Iterates over the body in chunks. If the body has previously
      # been read, this method can be called again and get the same
      # sequence of chunks.
      # @yield [chunk]
      # @yieldparam [String] chunk a chunk of the request body
      def each
        @request.body {|chunk| yield chunk }
      end
    end # class RequestBody
  end # module Adapters
end # module Webmachine

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webmachine-1.2.2 lib/webmachine/adapters/lazy_request_body.rb
webmachine-1.2.0 lib/webmachine/adapters/lazy_request_body.rb