# File lib/dm-serializer/to_csv.rb, line 55 def to_csv(*args) result = '' each do |item| result << item.to_csv(args.first) + "\n" end result end
# File lib/dm-serializer/to_json.rb, line 80 def to_json(*args) options = args.first options = {} unless options.kind_of?(Hash) resource_options = options.merge(:to_json => false) collection = map { |resource| resource.to_json(resource_options) } # default to making JSON if options.fetch(:to_json, true) MultiJson.encode(collection) else collection end end
# File lib/dm-serializer/to_xml.rb, line 93 def to_xml(opts = {}) to_xml_document(opts).to_s end
# File lib/dm-serializer/to_xml.rb, line 97 def to_xml_document(opts = {}) xml = DataMapper::Serializer::XML.serializer doc = xml.new_document default_collection_element_name = lambda { DataMapper::Inflector.pluralize(DataMapper::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
Generated with the Darkfish Rdoc Generator 2.