Sha256: 164fd5cf43d41af8704a212c342e43aac960b14353908ea07aea68d941a5edc5

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

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|
          controller = if target.respond_to?(:call)
            DialplanController.new(call).tap do |controller|
              controller.dialplan = target
            end
          else
            target.new call
          end

          call.execute_controller controller
        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.alpha1 lib/adhearsion/router/route.rb