class Hobby::Router::Routes

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/hobby/router/routes.rb, line 3
def initialize
  @patterns = {}
  super { |hash, key| hash[key] = find key }
end

Public Instance Methods

[]=(key, route) click to toggle source
Calls superclass method
# File lib/hobby/router/routes.rb, line 8
def []= key, route
  if key.include? ?:
    string = key.gsub(/(:\w+)/) { "(?<#{$1[1..-1]}>[^/?#.]+)" }
    @patterns[/^#{string}$/] = route
  else
    super and super "#{key}/", route
  end
end

Private Instance Methods

find(key) click to toggle source
# File lib/hobby/router/routes.rb, line 19
def find key
  _, route = @patterns.find { |pattern, _| pattern.match key }
  [route, $~.names.map(&:to_sym).zip($~.captures).to_h] if route
end