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)


65
66
67
# File 'lib/adhearsion/router/route.rb', line 65

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
58
59
# File 'lib/adhearsion/router/route.rb', line 28

def dispatch(call, callback = nil)
  Adhearsion::Events.trigger_immediately :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.alive? && 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
  }
rescue Call::Hangup, Call::ExpiredError
  logger.info "Call routing could not be completed because call was unavailable."
end

#evented?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/adhearsion/router/route.rb', line 61

def evented?
  false
end

#inspectObject Also known as: to_s



73
74
75
# File 'lib/adhearsion/router/route.rb', line 73

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)


69
70
71
# File 'lib/adhearsion/router/route.rb', line 69

def openended?
  false
end