Class: RubyEventStore::Browser::Router
- Inherits:
-
Object
- Object
- RubyEventStore::Browser::Router
- Defined in:
- lib/ruby_event_store/browser/router.rb
Defined Under Namespace
Classes: Route
Constant Summary collapse
- NoMatch =
Class.new(StandardError)
Instance Method Summary collapse
- #add_route(request_method, pattern, &block) ⇒ Object
- #handle(request) ⇒ Object
-
#initialize(urls = Urls.initial) ⇒ Router
constructor
A new instance of Router.
Constructor Details
Instance Method Details
#add_route(request_method, pattern, &block) ⇒ Object
43 44 45 |
# File 'lib/ruby_event_store/browser/router.rb', line 43 def add_route(request_method, pattern, &block) routes << Route.new(request_method, pattern, &block) end |
#handle(request) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/ruby_event_store/browser/router.rb', line 47 def handle(request) routes.each do |route| route_params = route.match(request) return route.call(request.params.merge(route_params), urls.with_request(request)) if route_params end raise NoMatch end |