Class: Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher
- Defined in:
- lib/adhearsion/voip/dsl/dialplan/dispatcher.rb
Overview
Serves as a EventCommand proxy for handling EventCommands. Useful if doing any pre-processing.
For example, when sending commands over the event socket to FreeSwitch, every command must start with “api”, but, when doing an originate, it must begin with an ampersand. These two pre-processors would be developed as separate CommandDispatchers.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
Instance Method Summary collapse
- #break!(uuid = @context) ⇒ Object
- #clone ⇒ Object
-
#def_keys!(hash) ⇒ Object
Takes a Hash and meta_def()‘s a method for each key that returns the key’s value in the Hash.
- #dispatch!(event_command) ⇒ Object
-
#initialize(factory, context = nil) ⇒ CommandDispatcher
constructor
A new instance of CommandDispatcher.
- #method_missing(name, *args, &block) ⇒ Object
- #return!(obj) ⇒ Object
Constructor Details
#initialize(factory, context = nil) ⇒ CommandDispatcher
Returns a new instance of CommandDispatcher.
64 65 66 67 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 64 def initialize(factory, context=nil) @context = context @factory = factory.new context end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 73 def method_missing(name, *args, &block) *commands = *@factory.send(name, *args, &block) commands.map do |command| if command.kind_of? Proc instance_eval(&command) elsif command.kind_of? EventCommand dispatched_command = dispatch! command if command.response_block while (new_cmd = command.response_block.call(dispatched_command)).kind_of? EventCommand dispatched_command = dispatch! new_cmd end end dispatched_command else command end end.last rescue ReturnValue => r return r.obj end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
62 63 64 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 62 def context @context end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
62 63 64 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 62 def factory @factory end |
Instance Method Details
#break!(uuid = @context) ⇒ Object
98 99 100 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 98 def break!(uuid=@context) raise NotImplementedError, "Must subclass #{self.class} and override this!" end |
#clone ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 110 def clone returning super do |nemesis| instance_variables.each do |iv| value = instance_variable_get(iv) nemesis.instance_variable_set iv, value.clone if value end end end |
#def_keys!(hash) ⇒ Object
Takes a Hash and meta_def()‘s a method for each key that returns the key’s value in the Hash.
104 105 106 107 108 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 104 def def_keys!(hash) hash.each_pair do |k,v| (k) { v } rescue nil end end |
#dispatch!(event_command) ⇒ Object
69 70 71 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 69 def dispatch!(event_command) raise NotImplementedError, "Must subclass #{self.class} and override this!" end |
#return!(obj) ⇒ Object
94 95 96 |
# File 'lib/adhearsion/voip/dsl/dialplan/dispatcher.rb', line 94 def return!(obj) raise DSL::Dialplan::ReturnValue.new(obj) end |