Sha256: cc3558dcf3548a5cb9bebe4e3246f7bd5b4e80f5063b8485fcb01123b0eb46f4
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 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 } 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
adhearsion-2.5.3 | lib/adhearsion/router/route.rb |
adhearsion-2.5.2 | lib/adhearsion/router/route.rb |