Sha256: 0cbf1e6e08dde2d212155a65209f981c165ad1ecdc35644d61a9c25736327233

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 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_actor|
            begin
              call_actor.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

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-2.0.1 lib/adhearsion/router/route.rb
adhearsion-2.0.0 lib/adhearsion/router/route.rb
adhearsion-2.0.0.rc5 lib/adhearsion/router/route.rb