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/utility.rb,
lib/adhearsion/call_controller/menu_dsl.rb,
lib/adhearsion/call_controller/menu_dsl/menu.rb,
lib/adhearsion/call_controller/output/player.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/calculated_match.rb,
lib/adhearsion/call_controller/menu_dsl/match_calculator.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/fixnum_match_calculator.rb,
lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb,
lib/adhearsion/call_controller/menu_dsl/calculated_match_collection.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Dial, Input, Output, Record, Utility
Constant Summary
Constants included from Record
Constants included from Output
Output::NoDocError, Output::PlaybackError
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
-
.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_call 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
#interruptible_play, #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!
Methods included from Input
Methods included from Dial
Constructor Details
#initialize(call, metadata = nil, &block) ⇒ CallController
Create a new instance
75 76 77 78 79 |
# File 'lib/adhearsion/call_controller.rb', line 75 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
81 82 83 84 85 86 87 |
# File 'lib/adhearsion/call_controller.rb', line 81 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.
57 58 59 |
# File 'lib/adhearsion/call_controller.rb', line 57 def call @call end |
#metadata ⇒ Hash (readonly)
Returns The controller’s metadata provided at invocation.
60 61 62 |
# File 'lib/adhearsion/call_controller.rb', line 60 def @metadata end |
Class Method Details
.exec(controller) ⇒ Object
Execute a call controller, allowing passing control to another controller
44 45 46 |
# File 'lib/adhearsion/call_controller.rb', line 44 def exec(controller) controller.exec end |
.mixin(mod) ⇒ Object
Include another module into all CallController classes
51 52 53 |
# File 'lib/adhearsion/call_controller.rb', line 51 def mixin(mod) include mod end |
Instance Method Details
#answer(*args) ⇒ Object
Answer the call
237 238 239 240 |
# File 'lib/adhearsion/call_controller.rb', line 237 def answer(*args) block_until_resumed call.answer(*args) end |
#bg_exec(completion_callback = nil) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/adhearsion/call_controller.rb', line 101 def bg_exec(completion_callback = nil) Celluloid::ThreadHandle.new do catching_standard_errors do exec_with_callback completion_callback end end end |
#eql?(other) ⇒ Boolean Also known as: ==
336 337 338 |
# File 'lib/adhearsion/call_controller.rb', line 336 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
92 93 94 95 96 97 98 99 |
# File 'lib/adhearsion/call_controller.rb', line 92 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
109 110 111 112 113 |
# File 'lib/adhearsion/call_controller.rb', line 109 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_call callbacks
247 248 249 250 251 |
# File 'lib/adhearsion/call_controller.rb', line 247 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.
178 179 180 181 182 |
# File 'lib/adhearsion/call_controller.rb', line 178 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.
144 145 146 147 |
# File 'lib/adhearsion/call_controller.rb', line 144 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).
304 305 306 307 308 309 310 |
# File 'lib/adhearsion/call_controller.rb', line 304 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
341 342 343 344 345 |
# File 'lib/adhearsion/call_controller.rb', line 341 def logger call.logger rescue Celluloid::DeadActorError super end |
#mute(*args) ⇒ Object
Mute the call
280 281 282 283 |
# File 'lib/adhearsion/call_controller.rb', line 280 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.
155 156 157 |
# File 'lib/adhearsion/call_controller.rb', line 155 def pass(controller_class, = nil) throw :pass_controller, controller_class.new(call, ) end |
#redirect(*args) ⇒ Object
Redirect the call to some other target
269 270 271 272 273 |
# File 'lib/adhearsion/call_controller.rb', line 269 def redirect(*args) block_until_resumed call.redirect(*args) raise Call::Hangup end |
#reject(*args) ⇒ Object
Reject the call
258 259 260 261 262 |
# File 'lib/adhearsion/call_controller.rb', line 258 def reject(*args) block_until_resumed call.reject(*args) raise Call::Hangup end |
#run ⇒ Object
Invoke the block supplied when creating the controller
133 134 135 |
# File 'lib/adhearsion/call_controller.rb', line 133 def run instance_exec(&block) if block end |
#stop_all_components ⇒ Object
Stop execution of all the components currently running in the controller.
162 163 164 165 166 167 168 169 170 |
# File 'lib/adhearsion/call_controller.rb', line 162 def stop_all_components logger.info "Stopping all controller components" @active_components.each do |component| begin component.stop! rescue Punchblock::Component::InvalidActionError end end end |
#unmute(*args) ⇒ Object
Unmute the call
290 291 292 293 |
# File 'lib/adhearsion/call_controller.rb', line 290 def unmute(*args) block_until_resumed call.unmute(*args) end |