| Class | Maveric::Router |
| In: |
maveric.rb
|
| Parent: | Object |
Storage of routes and routing mechanisms.
Matches the given path against the collection of routes. Returns nil the appropriate Route#route result with :controller mapped to the associated Controller.
# File maveric.rb, line 826
826: def [] path
827: ::Maveric.type_check :path, path, String
828: @routings.eject do |(r,c)|
829: b=r.route(path) and {:controller=>c}.update b
830: end
831: end
Places one or more routes to a Controller. Will generate a new Route if a route is a String. Accepts an Array for routes to add several at a time.
# File maveric.rb, line 804
804: def add routes, controller, opts={}
805: ::Maveric.log.info "#{self.class}#add"+
806: " #{routes.inspect} #{controller.inspect}"
807: ::Maveric.type_check :controller, controller, Class
808: ::Maveric.type_check :routes, routes, Array, String, ::Maveric::Route
809: routes = [routes] unless routes.is_a? Array
810: routes.flatten.map do |route|
811: ::Maveric.type_check :route, route, String, ::Maveric::Route
812: route = ::Maveric::Route.new route, opts if route.instance_of? String
813: @routings[route] = controller
814: end
815: end
Returns a list of the controllers with listed routes.
# File maveric.rb, line 797
797: def controllers
798: @routings.values.uniq
799: end