lib/ramaze/current.rb in ramaze-2008.06 vs lib/ramaze/current.rb in ramaze-2008.11

- old
+ new

@@ -1,10 +1,58 @@ require 'ramaze/current/request' require 'ramaze/current/response' require 'ramaze/current/session' module Ramaze + class Current + include Trinity + extend Trinity + + def initialize(app) + @app = app + end + + def call(env) + setup(env) + before_call + record + + @app.call(env) + finish + ensure + after_call + end + + def record + return unless filter = Global.record + request = Current.request + Record << request if filter.call(request) + end + + def setup(env) + self.request = Request.new(env) + self.response = Response.new + self.session = Session.new + end + + def finish + session.finish if session + response.finish + end + + def self.call(env) + end + + def before_call + end + + def after_call + end + end +end +__END__ + module Current class << self include Trinity def call(env) @@ -33,38 +81,30 @@ session.finish if session response.finish end def before(&block) - @before = block if block - @before + @before = block_given? ? block : @before end def before_call - if before - begin - before.call - rescue Object => e - Ramaze::Log.error e - raise - end - end + return unless before + before.call + rescue Object => e + Ramaze::Log.error e + raise e end def after(&block) - @after = block if block - @after + @after = block_given? ? block : @after end def after_call - if after - begin - after.call - rescue Object => e - Ramaze::Log.error e - raise - end - end + return unless after + after.call + rescue Object => e + Ramaze::Log.error e + raise e end end end end