lib/dm-serializer/to_xml.rb in dm-serializer-0.10.2 vs lib/dm-serializer/to_xml.rb in dm-serializer-1.0.0.rc1

- old
+ new

@@ -19,15 +19,15 @@ # add_property_node # add_node def to_xml_document(opts={}, doc = nil) xml = XMLSerializers::SERIALIZER doc ||= xml.new_document - default_xml_element_name = lambda { Extlib::Inflection.underscore(model.name).tr("/", "-") } + default_xml_element_name = lambda { ActiveSupport::Inflector.underscore(model.name).tr("/", "-") } root = xml.root_node(doc, opts[:element_name] || default_xml_element_name[]) properties_to_serialize(opts).each do |property| value = __send__(property.name) - attrs = (property.type == String) ? {} : {'type' => property.type.to_s.downcase} + attrs = (property.primitive == String) ? {} : {'type' => property.primitive.to_s.downcase} xml.add_node(root, property.name.to_s, value, attrs) end (opts[:methods] || []).each do |meth| if self.respond_to?(meth) @@ -42,33 +42,13 @@ end end end doc end - end - class Collection - def to_xml(opts = {}) - to_xml_document(opts).to_s - end - - def to_xml_document(opts = {}) - xml = DataMapper::Serialize::XMLSerializers::SERIALIZER - doc = xml.new_document - default_collection_element_name = lambda {Extlib::Inflection.pluralize(Extlib::Inflection.underscore(self.model.to_s)).tr("/", "-")} - root = xml.root_node(doc, opts[:collection_element_name] || default_collection_element_name[], {'type' => 'array'}) - self.each do |item| - item.to_xml_document(opts, doc) - end - doc - end - end - - if Serialize::Support.dm_validations_loaded? - - module Validate - class ValidationErrors + module ValidationErrors + module ToXml def to_xml(opts = {}) to_xml_document(opts).to_s end def to_xml_document(opts = {}) @@ -84,9 +64,36 @@ end end doc end + end + end + + end + + class Collection + def to_xml(opts = {}) + to_xml_document(opts).to_s + end + + def to_xml_document(opts = {}) + xml = DataMapper::Serialize::XMLSerializers::SERIALIZER + doc = xml.new_document + default_collection_element_name = lambda {ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(self.model.to_s)).tr("/", "-")} + root = xml.root_node(doc, opts[:collection_element_name] || default_collection_element_name[], {'type' => 'array'}) + self.each do |item| + item.to_xml_document(opts, doc) + end + doc + end + end + + if Serialize.dm_validations_loaded? + + module Validations + class ValidationErrors + include DataMapper::Serialize::ValidationErrors::ToXml end end end end