Class: Adhearsion::CallController
- 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/input/result.rb,
lib/adhearsion/call_controller/output/player.rb,
lib/adhearsion/call_controller/output/formatter.rb,
lib/adhearsion/call_controller/input/menu_builder.rb,
lib/adhearsion/call_controller/output/async_player.rb,
lib/adhearsion/call_controller/input/prompt_builder.rb,
lib/adhearsion/call_controller/output/abstract_player.rb,
lib/adhearsion/call_controller/input/ask_grammar_builder.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Dial, Input, Output, Record
Constant Summary
Constants included from Record
Constants included from Output
Output::NoDocError, Output::PlaybackError
Constants included from Input
Instance Attribute Summary collapse
-
#call ⇒ Call
readonly
The call object on which the controller is executing.
-
#metadata ⇒ Hash
readonly
The controller’s metadata provided at invocation.
Class Method Summary collapse
- .after_call(*args, &block) ⇒ Object
- .before_call(*args, &block) ⇒ Object
-
.exec(controller) ⇒ Object
Execute a call controller, allowing passing control to another controller.
-
.mixin(mod) ⇒ Object
Include another module into all CallController classes.
Instance Method Summary collapse
-
#answer(*args) ⇒ Object
Answer the call.
- #bg_exec(completion_callback = nil) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#exec(controller = self) ⇒ Object
Execute the controller, allowing passing control to another controller.
- #exec_with_callback(completion_callback = nil) ⇒ Object
-
#hangup(headers = nil) ⇒ Object
Hangup the call, and execute after callbacks.
-
#hard_pass(controller_class, metadata = nil) ⇒ Object
Cease execution of this controller, including any components it is executing, and pass to another.
-
#initialize(call, metadata = nil, &block) ⇒ CallController
constructor
Create a new instance.
-
#invoke(controller_class, metadata = nil) ⇒ Object
Invoke another controller class within this controller, returning to this context on completion.
-
#join(target, options = {}) ⇒ Object
Join the call to another call or a mixer, and block until the call is unjoined (by hangup or otherwise).
- #logger ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
-
#mute(*args) ⇒ Object
Mute the call.
-
#pass(controller_class, metadata = nil) ⇒ Object
Cease execution of this controller, and pass to another.
-
#redirect(*args) ⇒ Object
Redirect the call to some other target.
-
#reject(*args) ⇒ Object
Reject the call.
-
#run ⇒ Object
Invoke the block supplied when creating the controller.
-
#stop_all_components ⇒ Object
Stop execution of all the components currently running in the controller.
-
#unmute(*args) ⇒ Object
Unmute the call.
Methods included from Record
Methods included from Output
#locale, #locale=, #output_formatter, #play, #play!, #play_audio, #play_audio!, #play_document, #play_document!, #play_numeric, #play_numeric!, #play_time, #play_time!, #say, #say!, #say_characters, #say_characters!, #t
Methods included from Input
Methods included from Dial
Constructor Details
#initialize(call, metadata = nil, &block) ⇒ CallController
Create a new instance
83 84 85 86 87 |
# File 'lib/adhearsion/call_controller.rb', line 83 def initialize(call, = nil, &block) @call, @metadata, @block = call, || {}, block @block_context = eval "self", @block.binding if @block @active_components = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/adhearsion/call_controller.rb', line 89 def method_missing(method_name, *args, &block) if @block_context @block_context.send method_name, *args, &block else super end end |
Instance Attribute Details
#call ⇒ Call (readonly)
Returns The call object on which the controller is executing.
65 66 67 |
# File 'lib/adhearsion/call_controller.rb', line 65 def call @call end |
#metadata ⇒ Hash (readonly)
Returns The controller’s metadata provided at invocation.
68 69 70 |
# File 'lib/adhearsion/call_controller.rb', line 68 def @metadata end |
Class Method Details
.after_call(*args, &block) ⇒ Object
58 59 60 61 |
# File 'lib/adhearsion/call_controller.rb', line 58 def after_call(*args, &block) Adhearsion.deprecated :after after(*args, &block) end |
.before_call(*args, &block) ⇒ Object
53 54 55 56 |
# File 'lib/adhearsion/call_controller.rb', line 53 def before_call(*args, &block) Adhearsion.deprecated :before before(*args, &block) end |
.exec(controller) ⇒ Object
Execute a call controller, allowing passing control to another controller
42 43 44 |
# File 'lib/adhearsion/call_controller.rb', line 42 def exec(controller) controller.exec end |
.mixin(mod) ⇒ Object
Include another module into all CallController classes
49 50 51 |
# File 'lib/adhearsion/call_controller.rb', line 49 def mixin(mod) include mod end |
Instance Method Details
#answer(*args) ⇒ Object
Answer the call
240 241 242 243 |
# File 'lib/adhearsion/call_controller.rb', line 240 def answer(*args) block_until_resumed call.answer(*args) end |
#bg_exec(completion_callback = nil) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/adhearsion/call_controller.rb', line 109 def bg_exec(completion_callback = nil) Celluloid::ThreadHandle.new(Celluloid.actor_system) do catching_standard_errors do exec_with_callback completion_callback end end end |
#eql?(other) ⇒ Boolean Also known as: ==
339 340 341 |
# File 'lib/adhearsion/call_controller.rb', line 339 def eql?(other) other.instance_of?(self.class) && call == other.call && == other. end |
#exec(controller = self) ⇒ Object
Execute the controller, allowing passing control to another controller
100 101 102 103 104 105 106 107 |
# File 'lib/adhearsion/call_controller.rb', line 100 def exec(controller = self) new_controller = catch :pass_controller do controller.execute! nil end exec new_controller if new_controller end |
#exec_with_callback(completion_callback = nil) ⇒ Object
117 118 119 120 121 |
# File 'lib/adhearsion/call_controller.rb', line 117 def exec_with_callback(completion_callback = nil) exec ensure completion_callback.call call if completion_callback end |
#hangup(headers = nil) ⇒ Object
Hangup the call, and execute after callbacks
250 251 252 253 254 |
# File 'lib/adhearsion/call_controller.rb', line 250 def hangup(headers = nil) block_until_resumed call.hangup headers raise Call::Hangup end |
#hard_pass(controller_class, metadata = nil) ⇒ Object
Cease execution of this controller, including any components it is executing, and pass to another.
185 186 187 188 189 |
# File 'lib/adhearsion/call_controller.rb', line 185 def hard_pass(controller_class, = nil) logger.info "Hard passing with active components #{@active_components.inspect}" stop_all_components pass controller_class, end |
#invoke(controller_class, metadata = nil) ⇒ Object
Invoke another controller class within this controller, returning to this context on completion.
151 152 153 154 |
# File 'lib/adhearsion/call_controller.rb', line 151 def invoke(controller_class, = nil) controller = controller_class.new call, controller.run end |
#join(target, options = {}) ⇒ Object
Join the call to another call or a mixer, and block until the call is unjoined (by hangup or otherwise).
307 308 309 310 311 312 313 |
# File 'lib/adhearsion/call_controller.rb', line 307 def join(target, = {}) block_until_resumed async = (target.is_a?(Hash) ? target : ).delete :async join = call.join target, waiter = async ? join[:joined_condition] : join[:unjoined_condition] waiter.wait end |
#logger ⇒ Object
344 345 346 347 348 |
# File 'lib/adhearsion/call_controller.rb', line 344 def logger call.logger rescue Celluloid::DeadActorError super end |
#mute(*args) ⇒ Object
Mute the call
283 284 285 286 |
# File 'lib/adhearsion/call_controller.rb', line 283 def mute(*args) block_until_resumed call.mute(*args) end |
#pass(controller_class, metadata = nil) ⇒ Object
Cease execution of this controller, and pass to another.
162 163 164 |
# File 'lib/adhearsion/call_controller.rb', line 162 def pass(controller_class, = nil) throw :pass_controller, controller_class.new(call, ) end |
#redirect(*args) ⇒ Object
Redirect the call to some other target
272 273 274 275 276 |
# File 'lib/adhearsion/call_controller.rb', line 272 def redirect(*args) block_until_resumed call.redirect(*args) raise Call::Hangup end |
#reject(*args) ⇒ Object
Reject the call
261 262 263 264 265 |
# File 'lib/adhearsion/call_controller.rb', line 261 def reject(*args) block_until_resumed call.reject(*args) raise Call::Hangup end |
#run ⇒ Object
Invoke the block supplied when creating the controller
140 141 142 |
# File 'lib/adhearsion/call_controller.rb', line 140 def run instance_exec(&block) if block end |
#stop_all_components ⇒ Object
Stop execution of all the components currently running in the controller.
169 170 171 172 173 174 175 176 177 |
# File 'lib/adhearsion/call_controller.rb', line 169 def stop_all_components logger.info "Stopping all controller components" @active_components.each do |component| begin component.stop! rescue Adhearsion::Rayo::Component::InvalidActionError end end end |
#unmute(*args) ⇒ Object
Unmute the call
293 294 295 296 |
# File 'lib/adhearsion/call_controller.rb', line 293 def unmute(*args) block_until_resumed call.unmute(*args) end |