Sha256: 65c93fbd58143063ef4252d454eae35170a18ce73e244e3ad53dd951761b470c

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

# encoding: utf-8

require 'has_guarded_handlers'

module Adhearsion
  class Router
    class Route
      include HasGuardedHandlers

      attr_reader :name, :target, :guards

      def initialize(name, target = nil, *guards, &block)
        @name = name
        if block
          @target, @guards = block, ([target] + guards)
        else
          @target, @guards = target, guards
        end
        @guards.compact!
      end

      def match?(call)
        !guarded? guards, call
      end

      def dispatch(call, callback = nil)
        controller = if target.respond_to?(:call)
          CallController.new call, &target
        else
          target.new call
        end

        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
            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
      alias :to_s :inspect
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
adhearsion-2.1.3 lib/adhearsion/router/route.rb
adhearsion-2.1.2 lib/adhearsion/router/route.rb
adhearsion-2.1.1 lib/adhearsion/router/route.rb
adhearsion-2.1.0 lib/adhearsion/router/route.rb