class HTTP::Request::Body
def ==(other)
def ==(other) self.class == other.class && self.source == other.source # rubocop:disable Style/RedundantSelf end
def each(&block)
- Yieldparam: -
def each(&block) if @source.is_a?(String) yield @source elsif @source.respond_to?(:read) IO.copy_stream(@source, ProcIO.new(block)) @source.rewind if @source.respond_to?(:rewind) elsif @source.is_a?(Enumerable) @source.each(&block) end end
def initialize(source)
def initialize(source) @source = source validate_source_type! end
def size
-
(Integer)
-
def size if @source.is_a?(String) @source.bytesize elsif @source.respond_to?(:read) raise RequestError, "IO object must respond to #size" unless @source.respond_to?(:size) @source.size elsif @source.nil? 0 else raise RequestError, "cannot determine size of body: #{@source.inspect}" end end
def validate_source_type!
def validate_source_type! return if @source.is_a?(String) return if @source.respond_to?(:read) return if @source.is_a?(Enumerable) return if @source.nil? raise RequestError, "body of wrong type: #{@source.class}" end