Class: Navy::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/navy/router.rb

Defined Under Namespace

Classes: NullHandler, Routes

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|@routes| ... } ⇒ Router

Returns a new instance of Router.

Yields:

  • (@routes)


38
39
40
41
42
# File 'lib/navy/router.rb', line 38

def initialize(options = {})
  @routes = Routes.new
  @options = options
  yield @routes if block_given?
end

Instance Method Details

#route(request, options = {}) ⇒ Object



44
45
46
47
48
49
# File 'lib/navy/router.rb', line 44

def route(request, options = {})
  opts = @options.merge(options)
  handler, params = @routes.obtain(request.key)
  params = opts.merge params
  dispatch(handler, params, request)
end