1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

11 commits

Author SHA1 Message Date
prasath
47628ec128 replacing ordered hash to ruby hash 2012-02-08 00:34:47 +05:30
José Valim
5b2eb64ceb Revert "Implement ArraySerializer and move old serialization API to a new namespace."
This reverts commit 8896b4fdc8.

Conflicts:

	activemodel/lib/active_model.rb
	activemodel/lib/active_model/serializable.rb
	activemodel/lib/active_model/serializer.rb
	activemodel/test/cases/serializer_test.rb
2011-11-30 18:48:17 +01:00
José Valim
8896b4fdc8 Implement ArraySerializer and move old serialization API to a new namespace.
The following constants were renamed:

  ActiveModel::Serialization     => ActiveModel::Serializable
  ActiveModel::Serializers::JSON => ActiveModel::Serializable::JSON
  ActiveModel::Serializers::Xml  => ActiveModel::Serializable::XML

The main motivation for such a change is that `ActiveModel::Serializers::JSON`
was not actually a serializer, but a module that when included allows the target to be serializable to JSON.

With such changes, we were able to clean up the namespace to add true serializers as the ArraySerializer.
2011-11-23 23:18:15 +00:00
Nicolás Hock Isaza
da914fa35c Fixing as_json method for ActiveRecord models.
When you've got an AR Model and you override the `as_json` method,
you should be able to add default options to the renderer, like this:

    class User < ActiveRecord::Base
      def as_json(options = {})
        super(options.merge(:except => [:password_digest]))
      end
    end

This was not possible before this commit. See the added test case.
2011-09-29 21:44:23 -05:00
Matt Aimonetti
6e78bbea90 fixed a bug with the json serialization when the class setting is set to not include the root, but an instance is serialized with the root option passed as true 2011-09-22 14:05:25 -07:00
José Valim
51bef9d8fb to_xml should also rely on serializable hash. 2011-09-18 09:09:01 -07:00
John Firebaugh
4860143ee4 ActiveModel support for the :include serialization option
This commit moves support for the :include serialization option for
serializing associated objects out of ActiveRecord in into ActiveModel.
The following methods support the :include option:

  * serializable_hash
  * to_json
  * to_xml

Instances must respond to methods named by the values of the :includes
array (or keys of the :includes hash). If an association method returns
an object that is_a?(Enumerable) (which AR has_many associations do), it
is assumed to be a collection association, and its elements must respond
to :serializable_hash. Otherwise it must respond to :serializable_hash
itself.

While here, fix #858, XmlSerializer should not singularize already
singular association names.
2011-07-17 11:34:07 -07:00
Joe Fiorini
ac5e691153 Enable passing root: false to #to_json 2011-07-01 23:00:13 -04:00
Jim Herzberg
fbf99653f1 Attributes with :string type should not be given the type passed in model serialization options. Closes #1058 2011-05-18 15:52:55 -04:00
Joshua Wehner
2cef2d411a Methods that return nil should not be considered YAML 2011-05-10 12:06:09 -04:00
John Firebaugh
d907f3cb5c Rename test directory to match code directory
Hopefully "serializeration" is not an in joke that I missed.
2011-04-06 01:50:35 +08:00