| Module | Resourceful::Serialize::Array |
| In: |
lib/resourceful/serialize.rb
|
This module contains the definitions of serialize and to_serializable that are included in ActiveRecord::Base.
See the module documentation for Serialize for details.
# File lib/resourceful/serialize.rb, line 153
153: def serialize(format, options)
154: raise "Not all elements respond to to_serializable" unless all? { |e| e.respond_to? :to_serializable }
155: raise "Must specify :attributes option" unless options[:attributes]
156:
157: serialized = map { |e| e.to_serializable(options[:attributes]) }
158: root = first.class.to_s.pluralize.underscore
159:
160: if format == :xml
161: serialized.send("to_#{format}", :root => root)
162: else
163: {root => serialized}.send("to_#{format}")
164: end
165: end
See the module documentation for Serialize for details.
# File lib/resourceful/serialize.rb, line 168
168: def to_serializable(attributes)
169: if first.respond_to?(:to_serializable)
170: attributes = Serialize.normalize_attributes(attributes)
171: map { |e| e.to_serializable(attributes) }
172: else
173: self
174: end
175: end