From 095d95e36b3b4e4b2e5dddc51d6bada976534357 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Tue, 27 Nov 2007 20:26:48 -0800 Subject: [PATCH] refactored --- lib/sinatra.rb | 10 +++++++++- test/events_test.rb | 6 ++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/sinatra.rb b/lib/sinatra.rb index d6ba68a..100093b 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -1,5 +1,7 @@ module Sinatra + + Result = Struct.new(:body) class Event @@ -10,6 +12,10 @@ module Sinatra @block = b end + def invoke + Result.new(block.call) + end + end class Application @@ -26,7 +32,9 @@ module Sinatra end def lookup(method, path) - events[method].find { |e| e.path == path } + events[method].find do |e| + result = e.invoke and break result + end end end diff --git a/test/events_test.rb b/test/events_test.rb index 451dc76..d6da833 100644 --- a/test/events_test.rb +++ b/test/events_test.rb @@ -15,7 +15,9 @@ context "Simple Events" do result = application.lookup(:get, '/') - result.should.equal route - end + result.should.not.be.nil + result.body.should.equal 'Hello' + end + end -- 2.11.4.GIT