lib/atom/xml/parser.rb in ratom-0.2.1 vs lib/atom/xml/parser.rb in ratom-0.2.2
- old
+ new
@@ -5,10 +5,31 @@
# Please contact info@peerworks.org for further information.
#
require 'net/http'
+# Just a couple methods form transforming strings
+unless defined?(ActiveSupport)
+ class String # :nodoc:
+ def singularize
+ if self =~ /ies$/
+ self.sub(/ies$/, 'y')
+ else
+ self.sub(/s$/, '')
+ end
+ end
+
+ def demodulize
+ self.sub(/.*::/, '')
+ end
+
+ def constantize
+ Object.module_eval("::#{self}", __FILE__, __LINE__)
+ end
+ end
+end
+
module Atom
module Xml # :nodoc:
module Parseable # :nodoc:
def parse(xml, options = {})
starting_depth = xml.depth
@@ -37,12 +58,15 @@
def current_node_is?(xml, element, ns = nil)
xml.node_type == XML::Reader::TYPE_ELEMENT && xml.local_name == element && (ns.nil? || ns == xml.namespace_uri)
end
def Parseable.included(o)
- o.send(:cattr_accessor, :element_specs, :attributes)
- o.element_specs = {}
- o.attributes = []
+ o.class_eval do
+ def o.element_specs; @element_specs ||= {}; end
+ def o.attributes; @attributes ||= []; end
+ def element_specs; self.class.element_specs; end
+ def attributes; self.class.attributes; end
+ end
o.send(:extend, DeclarationMethods)
end
def ==(o)
if self.object_id == o.object_id