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

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

Returns a new instance of Route.



13
14
15
16
17
18
19
20
21
22
# File 'lib/adhearsion/router/route.rb', line 13

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

Instance Attribute Details

#controller_metadataObject

Returns the value of attribute controller_metadata.



11
12
13
# File 'lib/adhearsion/router/route.rb', line 11

def 
  @controller_metadata
end

#guardsObject (readonly)

Returns the value of attribute guards.



10
11
12
# File 'lib/adhearsion/router/route.rb', line 10

def guards
  @guards
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/adhearsion/router/route.rb', line 10

def name
  @name
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/adhearsion/router/route.rb', line 10

def target
  @target
end

Instance Method Details

#accepting?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/adhearsion/router/route.rb', line 63

def accepting?
  true
end

#dispatch(call, callback = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/adhearsion/router/route.rb', line 28

def dispatch(call, callback = nil)
  Adhearsion::Events.trigger :call_routed, call: call, route: self

  call_id = call.id # Grab this to use later incase the actor is dead

  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.active?
        if call_actor.auto_hangup
          logger.info "Call #{call_id} routing completed. Hanging up now."
          call_actor.hangup
        else
          logger.info "Call #{call_id} routing completed. Keeping the call alive at controller/router request."
        end
      else
        logger.info "Call #{call_id} routing completed. Call was already hung up."
      end
    rescue Call::Hangup, Call::ExpiredError
    end
    callback.call if callback
  }
end

#evented?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/adhearsion/router/route.rb', line 59

def evented?
  false
end

#inspectObject Also known as: to_s



71
72
73
# File 'lib/adhearsion/router/route.rb', line 71

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

#match?(call) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/adhearsion/router/route.rb', line 24

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

#openended?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/adhearsion/router/route.rb', line 67

def openended?
  false
end