class Rollerskates::Routing::Mapper
Public Class Methods
new(endpoints)
click to toggle source
# File lib/rollerskates/routing/mapper.rb, line 4 def initialize(endpoints) @endpoints = endpoints end
Public Instance Methods
map_to_route(request)
click to toggle source
# File lib/rollerskates/routing/mapper.rb, line 8 def map_to_route(request) @request = request path = request.path_info path[-1] = "" if path[-1] == "/" && path != "/" method = request.request_method.downcase.to_sym result = @endpoints[method].detect do |endpoint| match_path_with_pattern path, endpoint end return Route.new(@request, result[:klass_and_method]) if result end
match_path_with_pattern(path, endpoint)
click to toggle source
# File lib/rollerskates/routing/mapper.rb, line 19 def match_path_with_pattern(path, endpoint) regexp, placeholders = endpoint[:pattern] if path =~ regexp match_data = Regexp.last_match placeholders.each do |placeholder| @request.update_param(placeholder, match_data[placeholder]) end true end end