Class: Mgt::Routing::Mapper
Instance Method Summary collapse
-
#initialize(endpoints) ⇒ Mapper
constructor
A new instance of Mapper.
- #map_to_route(request) ⇒ Object
- #match_path_with_pattern(path, endpoint) ⇒ Object
Constructor Details
#initialize(endpoints) ⇒ Mapper
Returns a new instance of Mapper.
4 5 6 |
# File 'lib/routing/mapper.rb', line 4 def initialize(endpoints) @endpoints = endpoints end |
Instance Method Details
#map_to_route(request) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/routing/mapper.rb', line 8 def map_to_route(request) @request = request path = request.path_info 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) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/routing/mapper.rb', line 18 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 |