refactored

This commit is contained in:
Blake Mizerany 2007-11-27 20:26:48 -08:00
parent b17f5f7008
commit 095d95e36b
2 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -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