Class Maveric::Router
In: maveric.rb
Parent: Object

Storage of routes and routing mechanisms.


[]   add   controllers   new   to  

Public Class methods


     # File maveric.rb, line 792
792:   def initialize opts={}
793:     @routings =
794:   end

Public Instance methods

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: "#{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: do |route|
811:       ::Maveric.type_check :route, route, String, ::Maveric::Route
812:       route = 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

Return an array of routes mapped to a controller.


     # File maveric.rb, line 818
818:   def to controller
819:{|(r,d)| r if d == controller }.compact
820:   end