Class: Vundabar::Routing::Mapper
- Defined in:
- lib/vundabar/routing/mapper.rb
Instance Attribute Summary collapse
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #find_route(request) ⇒ Object
-
#initialize(endpoints) ⇒ Mapper
constructor
A new instance of Mapper.
- #match_path_with_endpoint(path, endpoint) ⇒ Object
Constructor Details
#initialize(endpoints) ⇒ Mapper
Returns a new instance of Mapper.
5 6 7 |
# File 'lib/vundabar/routing/mapper.rb', line 5 def initialize(endpoints) @endpoints = endpoints end |
Instance Attribute Details
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
4 5 6 |
# File 'lib/vundabar/routing/mapper.rb', line 4 def endpoints @endpoints end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
4 5 6 |
# File 'lib/vundabar/routing/mapper.rb', line 4 def request @request end |
Instance Method Details
#find_route(request) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/vundabar/routing/mapper.rb', line 9 def find_route(request) @request = request path = request.path_info method = request.request_method.downcase.to_sym endpoints[method].detect do |endpoint| match_path_with_endpoint path, endpoint end end |
#match_path_with_endpoint(path, endpoint) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vundabar/routing/mapper.rb', line 18 def match_path_with_endpoint(path, endpoint) regex, placeholders = endpoint[:pattern] if regex =~ path match_data = Regexp.last_match placeholders.each do |placeholder| request.update_param(placeholder, match_data[placeholder]) end true end end |