Sha256: 1cf032dd65ba57e562f3f0a7635cc15bbea838b8ae677dae1b3641147cb830cd

Contents?: true

Size: 732 Bytes

Versions: 12

Compression:

Stored size: 732 Bytes

Contents

module Evil::Client::Formatter
  #
  # Utility module to format file (IO) as a part of multipart body
  #
  # @example
  #   Evil::Client::Formatter::Form.call foo: { bar: :baz }
  #   # => "foo[bar]=baz"
  #
  module Multipart
    extend self
    require_relative "part"

    # Formats nested hash as a string
    #
    # @param  [Array<IO>] value
    # @option opts [String] :boundary
    # @return [String]
    #
    def call(*sources, boundary:, **)
      parts = sources.flatten.map.with_index(1) do |src, num|
        "--#{boundary}\r\n#{part(src, num)}"
      end

      [nil, nil, parts, "--#{boundary}--", nil].join("\r\n")
    end

    private

    def part(source, index)
      Part.call(source, index)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
evil-client-3.2.0 lib/evil/client/formatter/multipart.rb
evil-client-3.1.0 lib/evil/client/formatter/multipart.rb
evil-client-3.0.4 lib/evil/client/formatter/multipart.rb
evil-client-3.0.3 lib/evil/client/formatter/multipart.rb
evil-client-3.0.2 lib/evil/client/formatter/multipart.rb
evil-client-3.0.1 lib/evil/client/formatter/multipart.rb
evil-client-3.0.0 lib/evil/client/formatter/multipart.rb
evil-client-2.1.1 lib/evil/client/formatter/multipart.rb
evil-client-2.1.0 lib/evil/client/formatter/multipart.rb
evil-client-2.0.0 lib/evil/client/formatter/multipart.rb
evil-client-1.1.0 lib/evil/client/formatter/multipart.rb
evil-client-1.0.0 lib/evil/client/formatter/multipart.rb