Class: Punchblock::RayoNode
- Defined in:
- lib/punchblock/rayo_node.rb
Direct Known Subclasses
CommandNode, Component::Asterisk::AGI::Command::Param, Component::Asterisk::AMI::Action::Complete::Attribute, Component::Asterisk::AMI::Action::Param, Component::Input::Grammar, Event, Event::Asterisk::AMI::Event::Attribute, Event::Complete::Reason, Header, Ref
Constant Summary collapse
- InvalidNodeError =
Class.new Punchblock::Error
- @@registrations =
{}
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#component_id ⇒ Object
Returns the value of attribute component_id.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#original_component ⇒ Object
Returns the value of attribute original_component.
-
#target_call_id ⇒ Object
Returns the value of attribute target_call_id.
-
#target_mixer_name ⇒ Object
Returns the value of attribute target_mixer_name.
Class Method Summary collapse
-
.class_from_registration(name, ns = nil) ⇒ Class?
Find the class to use given the name and namespace of a stanza.
-
.import(node, call_id = nil, component_id = nil) ⇒ Object
Import an XML::Node to the appropriate class.
-
.new(name = registered_name, doc = nil) ⇒ Object
Create a new Node object.
-
.register(name, ns = nil) ⇒ Object
Register a new stanza class to a name and/or namespace.
Instance Method Summary collapse
- #eql?(o, *fields) ⇒ Boolean
- #inspect ⇒ Object (also: #to_s)
-
#inspect_attributes ⇒ Object
:nodoc:.
-
#source ⇒ RayoNode
The original command issued that lead to this event.
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
14 15 16 |
# File 'lib/punchblock/rayo_node.rb', line 14 def client @client end |
#component_id ⇒ Object
Returns the value of attribute component_id.
14 15 16 |
# File 'lib/punchblock/rayo_node.rb', line 14 def component_id @component_id end |
#connection ⇒ Object
Returns the value of attribute connection.
14 15 16 |
# File 'lib/punchblock/rayo_node.rb', line 14 def connection @connection end |
#domain ⇒ Object
Returns the value of attribute domain.
14 15 16 |
# File 'lib/punchblock/rayo_node.rb', line 14 def domain @domain end |
#original_component ⇒ Object
Returns the value of attribute original_component.
14 15 16 |
# File 'lib/punchblock/rayo_node.rb', line 14 def original_component @original_component end |
#target_call_id ⇒ Object
Returns the value of attribute target_call_id.
14 15 16 |
# File 'lib/punchblock/rayo_node.rb', line 14 def target_call_id @target_call_id end |
#target_mixer_name ⇒ Object
Returns the value of attribute target_mixer_name.
14 15 16 |
# File 'lib/punchblock/rayo_node.rb', line 14 def target_mixer_name @target_mixer_name end |
Class Method Details
.class_from_registration(name, ns = nil) ⇒ Class?
Find the class to use given the name and namespace of a stanza
35 36 37 |
# File 'lib/punchblock/rayo_node.rb', line 35 def self.class_from_registration(name, ns = nil) @@registrations[[name.to_s, ns]] end |
.import(node, call_id = nil, component_id = nil) ⇒ Object
Import an XML::Node to the appropriate class
Looks up the class the node should be then creates it based on the elements of the XML::Node
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/punchblock/rayo_node.rb', line 45 def self.import(node, call_id = nil, component_id = nil) node = Nokogiri::XML(node.to_xml).root if Punchblock.jruby? ns = (node.namespace.href if node.namespace) klass = class_from_registration(node.element_name, ns) if klass && klass != self klass.import node, call_id, component_id else new.inherit node end.tap do |event| event.target_call_id = call_id event.component_id = component_id end end |
.new(name = registered_name, doc = nil) ⇒ Object
Create a new Node object
not provided one will be created
65 66 67 68 |
# File 'lib/punchblock/rayo_node.rb', line 65 def self.new(name = registered_name, doc = nil) raise InvalidNodeError, "Trying to create a new #{self} with no name" unless name super name, doc, registered_ns end |
.register(name, ns = nil) ⇒ Object
Register a new stanza class to a name and/or namespace
This registers a namespace that is used when looking up the class name of the object to instantiate when a new stanza is received
24 25 26 27 28 |
# File 'lib/punchblock/rayo_node.rb', line 24 def self.register(name, ns = nil) self.registered_name = name.to_s self.registered_ns = ns.is_a?(Symbol) ? RAYO_NAMESPACES[ns] : ns @@registrations[[self.registered_name, self.registered_ns]] = self end |
Instance Method Details
#eql?(o, *fields) ⇒ Boolean
78 79 80 |
# File 'lib/punchblock/rayo_node.rb', line 78 def eql?(o, *fields) super o, *(fields + inspect_attributes) end |
#inspect ⇒ Object Also known as: to_s
74 75 76 |
# File 'lib/punchblock/rayo_node.rb', line 74 def inspect "#<#{self.class} #{inspect_attributes.map { |c| "#{c}=#{self.__send__(c).inspect rescue nil}" }.compact * ', '}>" end |
#inspect_attributes ⇒ Object
:nodoc:
70 71 72 |
# File 'lib/punchblock/rayo_node.rb', line 70 def inspect_attributes # :nodoc: [:target_call_id, :component_id, :target_mixer_name] end |
#source ⇒ RayoNode
Returns the original command issued that lead to this event.
85 86 87 88 |
# File 'lib/punchblock/rayo_node.rb', line 85 def source @source ||= client.find_component_by_id component_id if client && component_id @source ||= original_component end |