Parent

Included Modules

DataMapper::Collection

Public Instance Methods

to_csv(*args) click to toggle source
    # File lib/dm-serializer/to_csv.rb, line 55
55:     def to_csv(*args)
56:       result = ''
57:       each do |item|
58:         result << item.to_csv(args.first) + "\n"
59:       end
60:       result
61:     end
to_json(*args) click to toggle source
    # File lib/dm-serializer/to_json.rb, line 80
80:     def to_json(*args)
81:       options = args.first
82:       options = {} unless options.kind_of?(Hash)
83: 
84:       resource_options = options.merge(:to_json => false)
85:       collection = map { |resource| resource.to_json(resource_options) }
86: 
87:       # default to making JSON
88:       if options.fetch(:to_json, true)
89:         MultiJson.encode(collection)
90:       else
91:         collection
92:       end
93:     end
to_xml(opts = {}) click to toggle source
    # File lib/dm-serializer/to_xml.rb, line 93
93:     def to_xml(opts = {})
94:       to_xml_document(opts).to_s
95:     end
to_xml_document(opts = {}) click to toggle source
     # File lib/dm-serializer/to_xml.rb, line 97
 97:     def to_xml_document(opts = {})
 98:       xml = DataMapper::Serializer::XML.serializer
 99:       doc = xml.new_document
100: 
101:       default_collection_element_name = lambda {
102:         DataMapper::Inflector.pluralize(DataMapper::Inflector.underscore(self.model.to_s)).tr("/", "-")
103:       }
104: 
105:       root = xml.root_node(
106:         doc,
107:         opts[:collection_element_name] || default_collection_element_name[],
108:         {'type' => 'array'}
109:       )
110: 
111:       self.each do |item|
112:         item.to_xml_document(opts, doc)
113:       end
114: 
115:       doc
116:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.