lib/blather/xmpp_node.rb in blather-0.2 vs lib/blather/xmpp_node.rb in blather-0.2.1

- old
+ new

@@ -9,24 +9,10 @@ class_inheritable_accessor :xmlns, :name ## - # Automatically sets the namespace registered by the subclass - def self.new(name = nil, content = nil) - name ||= self.name - - args = [] - args << name.to_s if name - args << content if content - - elem = super *args - elem.xmlns = xmlns - elem - end - - ## # Lets a subclass register itself # # This registers a namespace that is used when looking # up the class name of the object to instantiate when a new # stanza is received @@ -55,21 +41,30 @@ new(node.element_name).inherit(node) end end ## + # Automatically sets the namespace registered by the subclass + def initialize(name = nil, content = nil) + name ||= self.class.name + content = content.to_s if content + + super name.to_s, content + self.xmlns = self.class.xmlns + end + + ## # Quickway of turning itself into a proper object def to_stanza self.class.import self end def xmlns=(ns) - attributes.remove :xmlns - self['xmlns'] = ns if ns + attributes['xmlns'] = ns end def xmlns - self['xmlns'] + attributes['xmlns'] end ## # Remove a child with the name and (optionally) namespace given def remove_child(name, ns = nil) \ No newline at end of file