lib/scrivito/future_binary.rb in scrivito_sdk-1.1.0.rc1 vs lib/scrivito/future_binary.rb in scrivito_sdk-1.1.0.rc2

- old
+ new

@@ -1,23 +1,28 @@ module Scrivito +# # @api public +# # The FutureBinary class represents the data to be stored in a binary field. # See {Scrivito::Binary.upload} and {Scrivito::Binary#copy} for details. +# +# @see Scrivito::Binary.upload +# @see Scrivito::Binary#copy +# class FutureBinary - attr_reader :filename, :content_type, :id_to_be_copied, :file_to_be_uploaded + attr_reader :filename, :content_type, :id_to_copy, :file_to_upload - def initialize(filename:, content_type:, id_to_be_copied: nil, file_to_be_uploaded: nil) - @filename = filename - @content_type = content_type || content_type_of_filename(filename) - @id_to_be_copied = id_to_be_copied - @file_to_be_uploaded = file_to_be_uploaded + def initialize(options = {}) + @filename, @content_type, @id_to_copy, @file_to_upload = + options.values_at(:filename, :content_type, :id_to_copy, :file_to_upload) end - private - - def content_type_of_filename(filename) - MIME::Types.type_for(filename).first.try(:content_type) + def to_h + { + filename: filename, + content_type: content_type, + }.compact end end end