Class: ZSS::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/zss/router.rb

Instance Method Summary collapse

Instance Method Details

#add(context, route, handler = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/zss/router.rb', line 4

def add(context, route, handler = nil)

  fail "Invalid context!" unless context
  fail "Invalid route: #{route}" unless route

  handler ||= route.to_sym

  fail "Invalid handler: #{handler}" unless context.respond_to? handler

  routes[route.to_s.upcase] = get_proc(context, handler)
end

#get(route) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/zss/router.rb', line 16

def get(route)
  handler = routes[route.to_s.upcase]
  return handler if handler

  error = Error[404]
  error.developer_message = "Invalid route #{route}!"
  fail error
end