Class: Adhearsion::CallController

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Autoload
Includes:
Dial, Input, Output, Record, Utility
Defined in:
lib/adhearsion/call_controller.rb,
lib/adhearsion/call_controller/dial.rb,
lib/adhearsion/call_controller/input.rb,
lib/adhearsion/call_controller/output.rb,
lib/adhearsion/call_controller/record.rb,
lib/adhearsion/call_controller/utility.rb,
lib/adhearsion/call_controller/menu_dsl.rb,
lib/adhearsion/call_controller/output/player.rb,
lib/adhearsion/call_controller/menu_dsl/menu.rb,
lib/adhearsion/call_controller/output/formatter.rb,
lib/adhearsion/call_controller/output/async_player.rb,
lib/adhearsion/call_controller/menu_dsl/menu_builder.rb,
lib/adhearsion/call_controller/output/abstract_player.rb,
lib/adhearsion/call_controller/menu_dsl/match_calculator.rb,
lib/adhearsion/call_controller/menu_dsl/calculated_match.rb,
lib/adhearsion/call_controller/menu_dsl/array_match_calculator.rb,
lib/adhearsion/call_controller/menu_dsl/range_match_calculator.rb,
lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb,
lib/adhearsion/call_controller/menu_dsl/fixnum_match_calculator.rb,
lib/adhearsion/call_controller/menu_dsl/calculated_match_collection.rb

Direct Known Subclasses

Adhearsion::Console::InteractiveController, SimonGame

Defined Under Namespace

Modules: Dial, Input, Output, Record, Utility

Constant Summary

Constant Summary

Constants included from Record

Record::RecordError

Constants included from Output

Output::PlaybackError

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Record

#record

Methods included from Output

#interruptible_play, #output_formatter, #play, #play!, #play_audio, #play_audio!, #play_numeric, #play_numeric!, #play_time, #play_time!, #say, #say!

Methods included from Input

#ask, #menu

Methods included from Dial

#dial

Constructor Details

- (CallController) initialize(call, metadata = nil, &block)

Create a new instance

Parameters:

  • call (Call)

    the call to operate the controller on

  • metadata (Hash) (defaults to: nil)

    generic key-value storage applicable to the controller

  • block

    to execute on the call



72
73
74
# File 'lib/adhearsion/call_controller.rb', line 72

def initialize(call,  = nil, &block)
  @call, @metadata, @block = call,  || {}, block
end

Instance Attribute Details

- (Object) call (readonly)

Returns the value of attribute call



57
58
59
# File 'lib/adhearsion/call_controller.rb', line 57

def call
  @call
end

- (Object) metadata (readonly)

Returns the value of attribute metadata



57
58
59
# File 'lib/adhearsion/call_controller.rb', line 57

def 
  @metadata
end

Class Method Details

+ (Object) exec(controller)

Execute a call controller, allowing passing control to another controller

Parameters:



45
46
47
# File 'lib/adhearsion/call_controller.rb', line 45

def exec(controller)
  controller.exec
end

+ (Object) mixin(mod)

Include another module into all CallController classes



52
53
54
# File 'lib/adhearsion/call_controller.rb', line 52

def mixin(mod)
  include mod
end

Instance Method Details

- (Object) answer(*args)

Answer the call



193
194
195
196
# File 'lib/adhearsion/call_controller.rb', line 193

def answer(*args)
  block_until_resumed
  call.answer(*args)
end

- (Object) bg_exec(completion_callback = nil)



88
89
90
91
92
93
94
# File 'lib/adhearsion/call_controller.rb', line 88

def bg_exec(completion_callback = nil)
  Celluloid::ThreadHandle.new do
    catching_standard_errors do
      exec_with_callback completion_callback
    end
  end
end

- (Boolean) eql?(other) Also known as: ==

Returns:

  • (Boolean)


273
274
275
# File 'lib/adhearsion/call_controller.rb', line 273

def eql?(other)
  other.instance_of?(self.class) && call == other.call &&  == other.
end

- (Object) exec(controller = self)

Execute the controller, allowing passing control to another controller



79
80
81
82
83
84
85
86
# File 'lib/adhearsion/call_controller.rb', line 79

def exec(controller = self)
  new_controller = catch :pass_controller do
    controller.execute!
    nil
  end

  exec new_controller if new_controller
end

- (Object) exec_with_callback(completion_callback = nil)



96
97
98
99
100
# File 'lib/adhearsion/call_controller.rb', line 96

def exec_with_callback(completion_callback = nil)
  exec
ensure
  completion_callback.call call if completion_callback
end

- (Object) hangup(headers = nil)

Hangup the call, and execute after_call callbacks

Parameters:

  • headers (Hash) (defaults to: nil)

Raises:



164
165
166
167
168
169
# File 'lib/adhearsion/call_controller.rb', line 164

def hangup(headers = nil)
  block_until_resumed
  call.hangup headers
  after_call
  raise Call::Hangup
end

- (Object) invoke(controller_class, metadata = nil)

Invoke another controller class within this controller, returning to this context on completion.

Parameters:

  • controller_class (Class)

    The class of controller to execute

  • metadata (Hash) (defaults to: nil)

    generic key-value storage applicable to the controller

Returns:

  • The return value of the controller's run method



130
131
132
133
# File 'lib/adhearsion/call_controller.rb', line 130

def invoke(controller_class,  = nil)
  controller = controller_class.new call, 
  controller.run
end

- (Object) join(target, options = {})

Join the call to another call or a mixer, and block until the call is unjoined (by hangup or otherwise).

Parameters:

  • target (Object)

    See Call#join for details

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :async (Boolean)

    Return immediately, without waiting for the calls to unjoin. Defaults to false.

See Also:



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/adhearsion/call_controller.rb', line 237

def join(target, options = {})
  block_until_resumed
  async = (target.is_a?(Hash) ? target : options).delete :async
  join_command = call.join target, options
  waiter = join_command.call_id || join_command.mixer_name
  if async
    call.wait_for_joined waiter
  else
    call.wait_for_unjoined waiter
  end
end

- (Object) logger



278
279
280
281
282
# File 'lib/adhearsion/call_controller.rb', line 278

def logger
  call.logger
rescue Celluloid::DeadActorError
  super
end

- (Object) mute(*args)

Mute the call



213
214
215
216
# File 'lib/adhearsion/call_controller.rb', line 213

def mute(*args)
  block_until_resumed
  call.mute(*args)
end

- (Object) pass(controller_class, metadata = nil)

Cease execution of this controller, and pass to another.

Parameters:

  • controller_class (Class)

    The class of controller to pass to

  • metadata (Hash) (defaults to: nil)

    generic key-value storage applicable to the controller



141
142
143
# File 'lib/adhearsion/call_controller.rb', line 141

def pass(controller_class,  = nil)
  throw :pass_controller, controller_class.new(call, )
end

- (Object) reject(*args)

Reject the call



203
204
205
206
# File 'lib/adhearsion/call_controller.rb', line 203

def reject(*args)
  block_until_resumed
  call.reject(*args)
end

- (Object) run

Invoke the block supplied when creating the controller



119
120
121
# File 'lib/adhearsion/call_controller.rb', line 119

def run
  instance_exec(&block) if block
end

- (Object) unmute(*args)

Unmute the call



223
224
225
226
# File 'lib/adhearsion/call_controller.rb', line 223

def unmute(*args)
  block_until_resumed
  call.unmute(*args)
end