Module: Mojito::Base
- Defined in:
- lib/mojito/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #env ⇒ Object
- #halt!(resp = response) ⇒ Object
- #initialize(request, options = {}) ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
Class Method Details
.included(type) ⇒ Object
9 10 11 |
# File 'lib/mojito/base.rb', line 9 def self.included(type) type.extend ClassMethods end |
Instance Method Details
#env ⇒ Object
24 25 26 |
# File 'lib/mojito/base.rb', line 24 def env request.env end |
#halt!(resp = response) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
#initialize(request, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mojito/base.rb', line 13 def initialize(request, = {}) @__request = case request when Rack::Request request.dup when Hash, Mash Rack::Request.new(request.dup) end @options = self.env['MOJITO/CONTEXT_PATH'] = self.env['SCRIPT_NAME'] end |
#request ⇒ Object
28 29 30 |
# File 'lib/mojito/base.rb', line 28 def request @__request end |
#response ⇒ Object
32 33 34 35 36 |
# File 'lib/mojito/base.rb', line 32 def response @__response ||= Rack::Response.new.tap do |res| res.headers.delete 'Content-Type' end end |