Class: Adhearsion::Router::Route

Inherits:
Object
  • Object
show all
Includes:
HasGuardedHandlers
Defined in:
lib/adhearsion/router/route.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Route) initialize(name, target = nil, *guards, &block)

A new instance of Route



10
11
12
13
14
15
16
17
18
# File 'lib/adhearsion/router/route.rb', line 10

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

Instance Attribute Details

- (Object) guards (readonly)

Returns the value of attribute guards



8
9
10
# File 'lib/adhearsion/router/route.rb', line 8

def guards
  @guards
end

- (Object) name (readonly)

Returns the value of attribute name



8
9
10
# File 'lib/adhearsion/router/route.rb', line 8

def name
  @name
end

- (Object) target (readonly)

Returns the value of attribute target



8
9
10
# File 'lib/adhearsion/router/route.rb', line 8

def target
  @target
end

Instance Method Details

- (Object) dispatcher



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/adhearsion/router/route.rb', line 24

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

- (Object) inspect Also known as: to_s



42
43
44
# File 'lib/adhearsion/router/route.rb', line 42

def inspect
  "#<#{self.class}:#{object_id} name=#{name} target=#{target} guards=#{guards}>"
end

- (Boolean) match?(call)

Returns:

  • (Boolean)


20
21
22
# File 'lib/adhearsion/router/route.rb', line 20

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