Sha256: b7db9de68bd10a984257ed70f6e7558fdf6bcf264a150420160a1fd5cce5934b

Contents?: true

Size: 716 Bytes

Versions: 11

Compression:

Stored size: 716 Bytes

Contents

module Ddr::Models
  class MediaType

    def self.call(file_or_path)
      path = file_or_path.respond_to?(:path) ? file_or_path.path : file_or_path
      # Use preferred media type, if available
      media_type = Ddr::Models.preferred_media_types[File.extname(path)]
      if !media_type
        if file_or_path.respond_to?(:content_type)
          # Rails ActionDispatch::Http::UploadedFile
          media_type = file_or_path.content_type
        else
          # Fall back to first MIME type or default
          mime_types = MIME::Types.of(path)
          media_type = mime_types.empty? ? Ddr::Models.default_mime_type : mime_types.first.content_type
        end
      end
      media_type
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ddr-models-2.10.2 lib/ddr/models/media_type.rb
ddr-models-2.10.1 lib/ddr/models/media_type.rb
ddr-models-2.10.0 lib/ddr/models/media_type.rb
ddr-models-2.10.0.rc2 lib/ddr/models/media_type.rb
ddr-models-2.10.0.rc1 lib/ddr/models/media_type.rb
ddr-models-2.9.2 lib/ddr/models/media_type.rb
ddr-models-2.9.1 lib/ddr/models/media_type.rb
ddr-models-2.9.0 lib/ddr/models/media_type.rb
ddr-models-2.9.0.rc1 lib/ddr/models/media_type.rb
ddr-models-2.8.0 lib/ddr/models/media_type.rb
ddr-models-2.8.0.rc1 lib/ddr/models/media_type.rb