| Module | Resourceful::Serialize::Model |
| 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 111
111: def serialize(format, options)
112: raise "Must specify :attributes option" unless options[:attributes]
113: hash = self.to_serializable(options[:attributes])
114: root = self.class.to_s.underscore
115: if format == :xml
116: hash.send("to_#{format}", :root => root)
117: else
118: {root => hash}.send("to_#{format}")
119: end
120: end
See the module documentation for Serialize for details.
# File lib/resourceful/serialize.rb, line 123
123: def to_serializable(attributes)
124: raise "Must specify attributes for #{self.inspect}.to_serializable" if attributes.nil?
125:
126: Serialize.normalize_attributes(attributes).inject({}) do |hash, (key, value)|
127: hash[key.to_s] = attr_hash_value(self.send(key), value)
128: hash
129: end
130: end