module Resourceful::Serialize::Array

This module contains the definitions of serialize and to_serializable that are included in ActiveRecord::Base.

Public Instance Methods

serialize format, options = {}, :attributes → [ ... ] click to toggle source

See the module documentation for Serialize for details.

# File lib/resourceful/serialize.rb, line 153
def serialize(format, options)
  raise "Not all elements respond to to_serializable" unless all? { |e| e.respond_to? :to_serializable }
  raise "Must specify :attributes option" unless options[:attributes]

  serialized = map { |e| e.to_serializable(options[:attributes]) }
  root = first.class.to_s.pluralize.underscore

  if format == :xml
    serialized.send("to_#{format}", :root => root)
  else
    {root => serialized}.send("to_#{format}")
  end
end
to_serializable(attributes) click to toggle source

See the module documentation for Serialize for details.

# File lib/resourceful/serialize.rb, line 168
def to_serializable(attributes)
  if first.respond_to?(:to_serializable)
    attributes = Serialize.normalize_attributes(attributes)
    map { |e| e.to_serializable(attributes) }
  else
    self
  end
end