lib/jellyfish.rb in jellyfish-0.5.3 vs lib/jellyfish.rb in jellyfish-0.6.0

- old
+ new

@@ -1,12 +1,11 @@ module Jellyfish - autoload :VERSION, 'jellyfish/version' - autoload :Sinatra, 'jellyfish/sinatra' + autoload :VERSION , 'jellyfish/version' + autoload :Sinatra , 'jellyfish/sinatra' + autoload :NewRelic, 'jellyfish/newrelic' - # ----------------------------------------------------------------- - class Response < RuntimeError def headers @headers ||= {'Content-Type' => 'text/html'} end @@ -26,32 +25,35 @@ end # ----------------------------------------------------------------- class Controller + module Call + def call env + @env = env + block_call(*dispatch) + end + + def block_call argument, block + ret = instance_exec(argument, &block) + body ret if body.nil? # prefer explicitly set values + body '' if body.nil? # at least give an empty string + [status || 200, headers || {}, body] + rescue LocalJumpError + jellyfish.log("Use `next' if you're trying to `return' or" \ + " `break' from the block.", env['rack.errors']) + raise + end + end + include Call + attr_reader :routes, :jellyfish, :env def initialize routes, jellyfish @routes, @jellyfish = routes, jellyfish @status, @headers, @body = nil end - def call env - @env = env - block_call(*dispatch) - end - - def block_call argument, block - ret = instance_exec(argument, &block) - body ret if body.nil? # prefer explicitly set values - body '' if body.nil? # at least give an empty string - [status || 200, headers || {}, body] - rescue LocalJumpError - jellyfish.log( - "Use `next' if you're trying to `return' or `break' from the block.", - env['rack.errors']) - raise - end - + def request ; @request ||= Rack::Request.new(env); end def forward ; raise(Jellyfish::NotFound.new) ; end def found url; raise(Jellyfish:: Found.new(url)); end alias_method :redirect, :found def path_info ; env['PATH_INFO'] || '/' ; end