Sha256: b3efa422c8b7c059076b319c7880a7bda75a0d9cc643c91524d7ca987cc07d99

Contents?: true

Size: 971 Bytes

Versions: 7

Compression:

Stored size: 971 Bytes

Contents

module Evil::Client::DSL
  # Nested definition for attached files
  class Files
    # Builds a final upload schema from request options
    #
    # @param  [Hash<Symbol, Object>] options
    # @return [Hash<Symbol, Object>]
    #
    def call(**options)
      @mutex.synchronize do
        @schema = []
        instance_exec(options, &@block)
        @schema
      end
    end

    private

    def initialize(&block)
      @mutex = Mutex.new
      @block = block
    end

    # ==========================================================================
    # Helper methods that mutate files @schema
    # ==========================================================================

    def add(data, type: "text/plain", charset: "utf-8", filename: nil, **)
      @schema << {
        file:     data.respond_to?(:read) ? data : StringIO.new(data),
        type:     MIME::Types[type].first,
        charset:  charset,
        filename: filename
      }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
evil-client-0.3.3 lib/evil/client/dsl/files.rb
evil-client-0.3.2 lib/evil/client/dsl/files.rb
evil-client-0.3.1 lib/evil/client/dsl/files.rb
evil-client-0.3.0 lib/evil/client/dsl/files.rb
evil-client-0.2.3 lib/evil/client/dsl/files.rb
evil-client-0.2.2 lib/evil/client/dsl/files.rb
evil-client-0.2.1 lib/evil/client/dsl/files.rb