Sha256: fde5f4f43edc3511c56226be93a0a402254b40a96e69003a722b3581055d88dc

Contents?: true

Size: 883 Bytes

Versions: 1

Compression:

Stored size: 883 Bytes

Contents

require "action_dispatch/http/mime_type" unless defined?(::Mime::Type)
require "multi_mime/adapter"
require "multi_mime/null_type"

module MultiMime
  module Adapters

    # Use the Mime::Type library
    class MimeType < Adapter

      #
      def type_for(mime_type, opts={})
        ::Mime::Type.parse_data_with_trailing_star(mime_type).first || MultiMime::NullType.new
      end

      #
      def type_for_extension(extension, opts={})
        extension = extension[/(?:.*\.)(.*$)/, 1] if extension.include?(".") # requires just the extension, without the dot
        ::Mime::Type.lookup_by_extension(extension) || MultiMime::NullType.new
      end

      #
      def type_for_path(path, opts={})
        type_for_extension(File.extname(path))
      end

      #
      def type_for_file(file, opts={})
        type_for_extension(File.extname(file))
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
multi_mime-0.0.2 lib/multi_mime/adapters/mime_type.rb