Sha256: 869d7fee2b6ef196bfcd8cf373c23240b2ae8c977abdf0f1f0eac83cbd4b9b4e

Contents?: true

Size: 849 Bytes

Versions: 15

Compression:

Stored size: 849 Bytes

Contents

module Jeanine
  class Mimes
    MimeTypeNotFound = Class.new(StandardError)
    MIME_TYPES_INVERTED = ::Rack::Mime::MIME_TYPES.invert

    def self.loaded?
      @loaded
    end

    def self.load!
      return if loaded?
      @loaded = true
      register(:json, Rack::Mime::MIME_TYPES[".json"])
      register(:html, Rack::Mime::MIME_TYPES[".html"])
      register(:text, Rack::Mime::MIME_TYPES[".text"])
      register(:plain, self.for(:text))
    end

    def self.register(type, header)
      mime_types[type] = header
    end

    def self.for(type)
      mime_types.fetch(type) do
        raise(MimeTypeNotFound, "Mime #{type} not registered")
      end
    end

    def self.mime_types
      @mime_types ||= {}
    end

    private_class_method :mime_types

    def initialize(*)
      raise "Should not be initialiazed"
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jeanine-0.8.1 lib/jeanine/mimes.rb
jeanine-0.8 lib/jeanine/mimes.rb
jeanine-0.7.8 lib/jeanine/mimes.rb
jeanine-0.7.7 lib/jeanine/mimes.rb
jeanine-0.7.6 lib/jeanine/mimes.rb
jeanine-0.7.5 lib/jeanine/mimes.rb
jeanine-0.7.4 lib/jeanine/mimes.rb
jeanine-0.7.3.2 lib/jeanine/mimes.rb
jeanine-0.7.3.1 lib/jeanine/mimes.rb
jeanine-0.7.3 lib/jeanine/mimes.rb
jeanine-0.7.2 lib/jeanine/mimes.rb
jeanine-0.7.1 lib/jeanine/mimes.rb
jeanine-0.7.0 lib/jeanine/mimes.rb
jeanine-0.6.0 lib/jeanine/mimes.rb
jeanine-0.5.0 lib/jeanine/mimes.rb