lib/adhearsion/router/route.rb in adhearsion-2.0.1 vs lib/adhearsion/router/route.rb in adhearsion-2.1.0
- old
+ new
@@ -1,7 +1,9 @@
# encoding: utf-8
+require 'has_guarded_handlers'
+
module Adhearsion
class Router
class Route
include HasGuardedHandlers
@@ -19,25 +21,41 @@
def match?(call)
!guarded? guards, call
end
- def dispatcher
- @dispatcher ||= lambda do |call, callback = nil|
- controller = if target.respond_to?(:call)
- CallController.new call, &target
- else
- target.new call
- end
+ def dispatch(call, callback = nil)
+ controller = if target.respond_to?(:call)
+ CallController.new call, &target
+ else
+ target.new call
+ end
- call.execute_controller controller, lambda { |call_actor|
- begin
+ call.accept if accepting?
+
+ call.execute_controller controller, lambda { |call_actor|
+ begin
+ if call_actor[:ahn_prevent_hangup]
+ logger.info "Call routing completed, keeping the call alive at controller/router request."
+ else
call_actor.hangup
- rescue Call::Hangup
end
- callback.call if callback
- }
- end
+ rescue Call::Hangup
+ end
+ callback.call if callback
+ }
+ end
+
+ def evented?
+ false
+ end
+
+ def accepting?
+ true
+ end
+
+ def openended?
+ false
end
def inspect
"#<#{self.class}:#{object_id} name=#{name} target=#{target} guards=#{guards}>"
end