Sha256: 2ace50e6c6ff0d7f3e4b6274161c90d0af26240d4da87eba289f4abca0f383a0

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

require 'rack/request'

module Jeanine
  class Request < Rack::Request
    FORMAT_REGEX = %r{\.(\w+)\z}

    def initialize(env)
      env['PATH_INFO'] = '/' if env['PATH_INFO'].empty?
      if env['PATH_INFO'].include?(".")
        format = env['PATH_INFO'].match(FORMAT_REGEX)
        if format
          @format = format.captures[0]
          env['PATH_INFO'].gsub!(FORMAT_REGEX, '')
        end
      end
      super
    end

    def params
      super.deep_transform_keys!(&:to_sym)
    end

    def post?
      request_method == 'POST'
    end

    def get?
      request_method == 'GET'
    end

    def delete?
      request_method == 'DELETE'
    end

    def put?
      request_method == 'PUT'
    end

    def patch?
      request_method == 'PATCH'
    end

    def options?
      request_method == 'options'
    end

    def head?
      request_method == 'head'
    end

    def json?
      format == 'json'
    end

    def mime_type
      @mime_type ||= Mimes::MIME_TYPES_INVERTED[content_type]
    end

    def format
      @format || Rack::Mime::MIME_TYPES[content_type]
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

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