diff --git a/lib/sinatra.rb b/lib/sinatra.rb new file mode 100644 index 00000000..d6ba68a4 --- /dev/null +++ b/lib/sinatra.rb @@ -0,0 +1,34 @@ + +module Sinatra + + class Event + + attr_reader :path, :block + + def initialize(path, &b) + @path = path + @block = b + end + + end + + class Application + + attr_reader :events + + def initialize + @events = Hash.new { |hash, key| hash[key] = [] } + end + + def define_event(method, path, &b) + events[method] << event = Event.new(path, &b) + event + end + + def lookup(method, path) + events[method].find { |e| e.path == path } + end + + end + +end \ No newline at end of file diff --git a/test/events_test.rb b/test/events_test.rb new file mode 100644 index 00000000..451dc760 --- /dev/null +++ b/test/events_test.rb @@ -0,0 +1,21 @@ +require File.dirname(__FILE__) + '/../lib/sinatra' + +require 'rubygems' +require 'test/spec' + +context "Simple Events" do + + specify "return what's at the end" do + + application = Sinatra::Application.new + + route = application.define_event(:get, '/') do + 'Hello' + end + + result = application.lookup(:get, '/') + + result.should.equal route + end + +end