refactored
This commit is contained in:
parent
b17f5f7008
commit
095d95e36b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue