Sha256: 7811086565bf05345b208cb4953836a5e87ca7ffdece718e37783e6acc96b7b8

Contents?: true

Size: 918 Bytes

Versions: 10

Compression:

Stored size: 918 Bytes

Contents

module JasnyBundle
  class MimeTypes
    DEFAULT_TYPE = 'application/octet-stream'
    MIME_TYPES = {
      '.eot' => 'application/vnd.ms-fontobject',
      '.svg' => 'image/svg+xml',
      '.ttf' => 'application/x-font-ttf',
      '.otf' => 'application/x-font-otf',
      '.woff' => 'application/x-font-woff'
    }

    def initialize(types, default = DEFAULT_TYPE.dup)
      @types = types.dup
      @default = default

      MIME_TYPES.each_pair do |extension, type|
        set extension, type
      end
    end

    def [](extension)
      @types.fetch(extension, DEFAULT_TYPE.dup).dup
    end

    def font?(extension)
      MIME_TYPES.keys.include? extension
    end

    def set(extension, mime_type)
      if @types[extension].nil? || @types[extension] == @default
        set!(extension, mime_type)
      end
    end

    def set!(extension, mime_type)
      @types[extension] = mime_type
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
jasny_bundle_fixed-1.0.0 lib/jasny_bundle/mime_types.rb
jasny_bundle-2.1.0 lib/jasny_bundle/mime_types.rb
jasny_bundle-2.0.2 lib/jasny_bundle/mime_types.rb
jasny_bundle-2.0.1 lib/jasny_bundle/mime_types.rb
jasny_bundle-2.0.0 lib/jasny_bundle/mime_types.rb
jasny_bundle-1.4.0 lib/jasny_bundle/mime_types.rb
jasny_bundle-1.3.1 lib/jasny_bundle/mime_types.rb
jasny_bundle-1.2.0 lib/jasny_bundle/mime_types.rb
jasny_bundle-1.1.1 lib/jasny_bundle/mime_types.rb
jasny_bundle-1.0.2 lib/jasny_bundle/mime_types.rb