Class: Strelka::Router

Inherits:
Object
  • Object
show all
Extended by:
Loggability, Pluggability, AbstractClass
Defined in:
lib/strelka/router.rb

Overview

Abstract base class for pluggable routing strategies for the Routing plugin.

This class can't be instantiated itself, but it does act as a factory for loading and instantiating its subclasses:

# Create an instance of the default router strategy with the given
# routes and options.
Strelka::Router.create( 'default', routes, options )

To define your own strategy, you'll need to inherit this class, name it Strelka::Router::{Something}, save it in a file named strelka/router/{something}.rb, and be sure to override the #add_route and #route_request methods.

Direct Known Subclasses

Default

Defined Under Namespace

Classes: Default, Exclusive

Instance Method Summary collapse

Methods included from AbstractClass

extended, included, inherited, pure_virtual

Constructor Details

#initialize(routes = [], options = {}) ⇒ Router

Create a new router that will route requests according to the specified routes.

If the optional options hash is specified, it is passed to the router strategy.



43
44
45
46
47
48
# File 'lib/strelka/router.rb', line 43

def initialize( routes=[], options={} )
	routes.each do |tuple|
		self.log.debug "  adding route: %p" % [ tuple ]
		self.add_route( *tuple )
	end
end

Instance Method Details

#add_routeObject

:call-seq:

add_route( http_verb, path_array, routing_info )

Add a route for the specified http_verb, path_array, and routing_info. The http_verb will be one of the methods from RFC 2616 as a Symbol (e.g., :GET, :DELETE). The path_array will be the route path split up by path separator. The routing_info is a Hash that contains the action that will be run when the route matches, routing options, and any other routing information associated with the route.



66
# File 'lib/strelka/router.rb', line 66

pure_virtual :add_route

#route_requestObject

:call-seq:

route_request( request )

Determine the most-specific route for the specified request and return the routing info Hash.



75
# File 'lib/strelka/router.rb', line 75

pure_virtual :route_request