Class: Hobby::Router::Routes

Inherits:
Hash
  • Object
show all
Defined in:
lib/hobby/router/routes.rb

Instance Method Summary collapse

Constructor Details

#initializeRoutes

Returns a new instance of Routes.



3
4
5
6
# File 'lib/hobby/router/routes.rb', line 3

def initialize
  @patterns = {}
  super { |hash, key| hash[key] = find key }
end

Instance Method Details

#[]=(key, route) ⇒ Object



8
9
10
11
12
13
14
15
# 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