Class: Navy::Router::Routes
- Inherits:
-
Object
- Object
- Navy::Router::Routes
- Defined in:
- lib/navy/router.rb
Instance Method Summary collapse
Instance Method Details
#maps ⇒ Object
11 12 13 |
# File 'lib/navy/router.rb', line 11 def maps @maps ||= {} end |
#obtain(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/navy/router.rb', line 15 def obtain(path) @maps.each do |pattern, handler| matches = pattern.match(path) if matches params = extract_params(matches) return handler.new, params end end return NullHandler.new, {} end |
#route(pattern, handlers) ⇒ Object
5 6 7 8 9 |
# File 'lib/navy/router.rb', line 5 def route(pattern, handlers) pattern = pattern.gsub(/:([a-z]+)/, '(?<\1>[a-z0-9\-_]+)') regex = Regexp.new(pattern) maps[regex] = handlers end |