Sha256: 8f9df4abdc50b643b214e56ff4c91efb7ca1720e9e696b9955290a6eee216ddc
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
# encoding: utf-8 require 'has_guarded_handlers' module Adhearsion class Router class Route include HasGuardedHandlers attr_reader :name, :target, :guards attr_accessor :controller_metadata def initialize(name, target = nil, *guards, &block) @name = name if block @target, @guards = block, ([target] + guards) else @target, @guards = target, guards end @guards.compact! @controller_metadata = nil end def match?(call) !guarded? guards, call end def dispatch(call, callback = nil) Adhearsion::Events.trigger_immediately :call_routed, call: call, route: self controller = if target.respond_to?(:call) CallController.new call, controller_metadata, &target else target.new call, controller_metadata end call.accept if accepting? call.execute_controller controller, lambda { |call_actor| begin if call_actor.auto_hangup logger.info "Call #{call.id} routing completed. Hanging up now." call_actor.hangup else logger.info "Call #{call.id} routing completed. Keeping the call alive at controller/router request." end rescue Call::Hangup, Call::ExpiredError end callback.call if callback } rescue Call::Hangup, Call::ExpiredError logger.info "Call routing could not be completed because call was unavailable." 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 alias :to_s :inspect end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
adhearsion-2.5.4 | lib/adhearsion/router/route.rb |