Class: RapidRunty::Router::Matcher
- Defined in:
- lib/rapid_runty/router/matcher.rb
Overview
Matches passed in path with array of application paths
Instance Method Summary collapse
- #controller_action(options) ⇒ Object
-
#match(path, routes) ⇒ matching_route, ...
Defines the route that matches the path.
Instance Method Details
#controller_action(options) ⇒ Object
37 38 39 40 41 |
# File 'lib/rapid_runty/router/matcher.rb', line 37 def controller_action() Hash[ %w(controller action).zip .split('#') ] end |
#match(path, routes) ⇒ matching_route, ...
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" }]
Currently only supporting “:to” options which defines the “controller#action”
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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.) ] if pattern == path end [nil, {}, {}] end |