Sha256: 0761dbdff6839e88013dc00bc833c3f09f81e4d2d7b7fe5c278f9477bc12c749

Contents?: true

Size: 705 Bytes

Versions: 43

Compression:

Stored size: 705 Bytes

Contents

module Ddr
  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.preferred_media_types[(::File.extname(path)).downcase]
      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.default_mime_type : mime_types.first.content_type
        end
      end
      media_type
    end

  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
ddr-core-1.17.0 app/models/ddr/media_type.rb
ddr-core-1.16.0 app/models/ddr/media_type.rb
ddr-core-1.15.0 app/models/ddr/media_type.rb
ddr-core-1.14.0 app/models/ddr/media_type.rb
ddr-core-1.13.2 app/models/ddr/media_type.rb
ddr-core-1.13.1 app/models/ddr/media_type.rb
ddr-core-1.13.0 app/models/ddr/media_type.rb
ddr-core-1.12.2 app/models/ddr/media_type.rb
ddr-core-1.12.1 app/models/ddr/media_type.rb
ddr-core-1.12.0 app/models/ddr/media_type.rb
ddr-core-1.11.0 app/models/ddr/media_type.rb
ddr-core-1.10.0 app/models/ddr/media_type.rb
ddr-core-1.9.0 app/models/ddr/media_type.rb
ddr-core-1.8.0 app/models/ddr/media_type.rb
ddr-core-1.7.0 app/models/ddr/media_type.rb
ddr-core-1.6.6 app/models/ddr/media_type.rb
ddr-core-1.6.5 app/models/ddr/media_type.rb
ddr-core-1.6.4 app/models/ddr/media_type.rb
ddr-core-1.6.3 app/models/ddr/media_type.rb
ddr-core-1.6.2 app/models/ddr/media_type.rb