class Adhearsion::Router
Constants
- NoMatchError
Attributes
routes[R]
Public Class Methods
new(&block)
click to toggle source
# File lib/adhearsion/router.rb, line 16 def initialize(&block) @routes = [] instance_exec(&block) end
Public Instance Methods
handle(call)
click to toggle source
# File lib/adhearsion/router.rb, line 31 def handle(call) raise NoMatchError unless route = match(call) logger.info "Call #{call.id} selected route \"#{route.name}\" (#{route.target})" route.dispatch call rescue NoMatchError logger.warn "Call #{call.id} could not find a matching route. Rejecting." call.reject :error end
match(call)
click to toggle source
# File lib/adhearsion/router.rb, line 27 def match(call) @routes.find { |route| route.match? call } end
route(*args, &block)
click to toggle source
# File lib/adhearsion/router.rb, line 21 def route(*args, &block) Route.new(*args, &block).tap do |route| @routes << route end end