class RapidRunty::Router::Matcher
Matches passed in path with array of application paths
Public Instance Methods
controller_action(options)
click to toggle source
# File lib/rapid_runty/router/matcher.rb, line 37 def controller_action(options) Hash[ %w(controller action).zip options.split('#') ] end
match(path, routes)
click to toggle source
Defines the route that matches the path
Example:
RapidRunty::Router::Matcher.new.match("/foo", [{url: "/", to: "root#index"}, {url: "/bar", to: "bar#index"}, {url: "/foo", to: "foo#index"}]) #=> ["/foo", [], { controller: "foo", action: "index" }] RapidRunty::Router::Matcher.new.match("/04/01/01", [{url: "/:day/:month/:year", to: "date#find"}]) #=> ["/", ["04", "01", "01"], { controller: "date", action: "find" }]
@param path [String] path from ENV @param application routes [Array] Array of Hash application defined routes
Currently only supporting “:to” options which defines the “controller#action”
@return [matching_route, matched_placeholders, matched_controller_action] array
# File lib/rapid_runty/router/matcher.rb, line 22 def match(path, routes) path = route_parser.new(path) url_patterns = routes.map { |route| route_parser.new(route) } url_patterns.each do |pattern| return [ pattern.to_s, pattern.placeholders, controller_action(pattern.options) ] if pattern == path end [nil, {}, {}] end
Private Instance Methods
route_parser()
click to toggle source
# File lib/rapid_runty/router/matcher.rb, line 45 def route_parser RapidRunty::Router::RouteParser end