Class: Adhearsion::Console
- Inherits:
-
Object
- Object
- Adhearsion::Console
- Includes:
- Singleton
- Defined in:
- lib/adhearsion/console.rb
Instance Attribute Summary (collapse)
-
- (Object) input
Returns the value of attribute input.
Class Method Summary (collapse)
- + (Object) method_missing(method, *args, &block)
-
+ (Object) mixin(mod)
Include another external functionality into the console.
Instance Method Summary (collapse)
- - (Object) calls
-
- (Console) initialize
constructor
A new instance of Console.
- - (Boolean) libedit?
- - (Object) log_level(level = nil)
-
- (Object) run
Start the Adhearsion console.
- - (Object) shutdown!
- - (Object) stop
- - (Object) take(call = nil)
Constructor Details
- (Console) initialize
A new instance of Console
25 26 27 |
# File 'lib/adhearsion/console.rb', line 25 def initialize @input = $stdin end |
Instance Attribute Details
- (Object) input
Returns the value of attribute input
23 24 25 |
# File 'lib/adhearsion/console.rb', line 23 def input @input end |
Class Method Details
+ (Object) method_missing(method, *args, &block)
18 19 20 |
# File 'lib/adhearsion/console.rb', line 18 def method_missing(method, *args, &block) instance.send method, *args, &block end |
+ (Object) mixin(mod)
Include another external functionality into the console
14 15 16 |
# File 'lib/adhearsion/console.rb', line 14 def mixin(mod) include mod end |
Instance Method Details
- (Object) calls
64 65 66 |
# File 'lib/adhearsion/console.rb', line 64 def calls Adhearsion.active_calls end |
- (Boolean) libedit?
104 105 106 107 108 109 110 111 112 |
# File 'lib/adhearsion/console.rb', line 104 def libedit? begin # If NotImplemented then this might be libedit Readline.emacs_editing_mode false rescue NotImplementedError true end end |
- (Object) log_level(level = nil)
52 53 54 55 56 57 58 |
# File 'lib/adhearsion/console.rb', line 52 def log_level(level = nil) if level Adhearsion::Logging.level = level else ::Logging::LEVELS.invert[Adhearsion::Logging.level].to_sym end end |
- (Object) run
Start the Adhearsion console
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/adhearsion/console.rb', line 32 def run set_prompt Pry.config.command_prefix = "%" if libedit? logger.error "Cannot start. You are running Adhearsion on Ruby with libedit. You must use readline for the console to work." else logger.info "Launching Adhearsion Console" @pry_thread = Thread.current pry logger.info "Adhearsion Console exiting" end end |
- (Object) shutdown!
60 61 62 |
# File 'lib/adhearsion/console.rb', line 60 def shutdown! Process.shutdown! end |
- (Object) stop
45 46 47 48 49 50 |
# File 'lib/adhearsion/console.rb', line 45 def stop return unless instance_variable_defined?(:@pry_thread) @pry_thread.kill @pry_thread = nil logger.info "Adhearsion Console shutting down" end |
- (Object) take(call = nil)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/adhearsion/console.rb', line 68 def take(call = nil) case call when Call interact_with_call call when String if call = calls[call] interact_with_call call else logger.error "An active call with that ID does not exist" end when nil case calls.size when 0 logger.warn "No calls active to take" when 1 interact_with_call calls.values.first else puts "Please choose a call:" puts "# (inbound/outbound) details" current_calls = calls.values current_calls.each_with_index do |active_call, index| puts "#{index}: (#{active_call.is_a?(OutboundCall) ? 'o' : 'i' }) #{active_call.id} from #{active_call.from} to #{active_call.to}" end print "#> " index = input.gets.chomp.to_i call = current_calls[index] interact_with_call call end else raise ArgumentError end ensure set_prompt pry end |