Sha256: 42c4525b0188bc21e4715f69b371d88c5821144ead167764e8989557cb1d9017

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8

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 dispatcher
        @dispatcher ||= lambda do |call, callback = nil|
          controller = if target.respond_to?(:call)
            CallController.new call, &target
          else
            target.new call
          end

          call.execute_controller controller, lambda { |call|
            begin
              call.hangup
            rescue Call::Hangup
            end
            callback.call if callback
          }
        end
      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.0.0.rc4 lib/adhearsion/router/route.rb