Class: Adhearsion::Router
- Includes:
- Filters
- Defined in:
- lib/adhearsion/router.rb,
lib/adhearsion/router/route.rb,
lib/adhearsion/router/evented_route.rb,
lib/adhearsion/router/openended_route.rb,
lib/adhearsion/router/unaccepting_route.rb
Defined Under Namespace
Modules: EventedRoute, Filters, OpenendedRoute, UnacceptingRoute Classes: FilteredRouter, Route
Constant Summary collapse
- NoMatchError =
Class.new Adhearsion::Error
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #handle(call) ⇒ Object
-
#initialize(&block) ⇒ Router
constructor
A new instance of Router.
- #match(call) ⇒ Object
- #route(*args, &block) ⇒ Object
Methods included from Filters
#evented, #filtered_routes, #openended, #unaccepting
Constructor Details
#initialize(&block) ⇒ Router
Returns a new instance of Router.
16 17 18 19 |
# File 'lib/adhearsion/router.rb', line 16 def initialize(&block) @routes = [] instance_exec(&block) end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
14 15 16 |
# File 'lib/adhearsion/router.rb', line 14 def routes @routes end |
Instance Method Details
#handle(call) ⇒ Object
31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
27 28 29 |
# File 'lib/adhearsion/router.rb', line 27 def match(call) @routes.find { |route| route.match? call } end |