module Mojito::Base

Public Class Methods

included(type) click to toggle source
# File lib/mojito/base.rb, line 9
def self.included(type)
        type.extend ClassMethods
end
new(request, options = {}) click to toggle source
# File lib/mojito/base.rb, line 13
def initialize(request, options = {})
        @__request = case request 
        when Rack::Request
                request.dup
        when Hash, Mash
                Rack::Request.new(request.dup)
        end
        @options = options
        self.env['MOJITO/CONTEXT_PATH'] = self.env['SCRIPT_NAME']
end

Public Instance Methods

env() click to toggle source
# File lib/mojito/base.rb, line 24
def env
        request.env
end
halt!(resp = response) click to toggle source
# File lib/mojito/base.rb, line 38
def halt!(resp = response)
        throw :halt, case resp
        when Rack::Response
                resp.tap {|res|
                        unless res.headers.include? 'Content-Type'
                                if extension = request.path[/(?<=\.)\w+$/] and res.status == 200 and type = MIME::Types.type_for(extension).first
                                        res.headers['Content-Type'] = type.to_s
                                else
                                        res.headers['Content-Type'] = 'text/html'
                                end
                        end
                }.finish
        when Array
                resp
        when Symbol, Integer
                response.status = STATUS[resp].code
                response.finish
        else
                [500, { 'Content-Type' => 'text/plain', 'Content-Length' => '0' }, []]
        end
end
request() click to toggle source
# File lib/mojito/base.rb, line 28
def request
        @__request
end
response() click to toggle source
# File lib/mojito/base.rb, line 32
def response
        @__response ||= Rack::Response.new.tap do |res|
                res.headers.delete 'Content-Type'
        end
end