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

22 commits

Author SHA1 Message Date
Derek Hammer
a469ec787c Adding documentation to clarify usage of attributes hash.
Serialization uses only the attributes hash's keys and calls
methods that are of the same name as the keys on the serialized
object.
2012-02-12 08:08:09 -06:00
Rafael Mendonça França
2a663dcf09 Remove Array.wrap call in ActiveModel 2012-01-06 01:04:33 -03:00
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
zhengjia
1adf5662b5 Fixed serialization issues with multiple includes with options 2011-10-11 11:09:43 -05:00
José Valim
d4457dc32b Provide read_attribute_for_serialization as the API to serialize attributes. 2011-09-30 14:20:41 +02:00
Jon Leighton
a15424b92c Make serializable_hash take attr values directly from attributes hash.
Previously, it would use send() to get the attribute. In Active
Resource, this would rely on hitting method missing. If a method with
the same name was defined further up the ancestor chain, that method
would wrongly be called.

This change fixes test_to_xml_with_private_method_name_as_attribute in
activeresource/test/cases/base_test.rb, which was broken after
51bef9d8fb, because that change made
to_xml use serializable_hash.
2011-09-26 12:40:03 +01:00
Anand
1be3442a0a added missing require array/wrap in serialization 2011-08-23 16:30:02 +05:30
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
John Firebaugh
cbf924ef08 Replace map+compact with select 2011-07-17 11:34:06 -07:00
John Firebaugh
da4e1faf6f serializable_hash(:only => [], :methods => [:foo]) should work 2011-07-17 11:34:06 -07:00
Sebastian Martinez
2a4b780ab1 Remove extra white spaces on ActiveModel docs. 2011-05-23 20:39:10 -03:00
Nathaniel Bibler
285fdbae2b Fixed broken, memoized attributes method example
[#6245 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-02-07 14:44:37 -02:00
Akira Matsuda
a3fbbb626f 'nil' => nil 2010-12-17 14:37:22 +09:00
Emilio Tagua
dc2f26ca38 Perf: refactor methods using inject when not need in activemodel.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2010-09-22 18:08:03 -03:00
Jakub Suder
2524cf404c fixed some issues with JSON encoding
- as_json in ActiveModel should return a hash
  and handle :only/:except/:methods options
- Array and Hash should call as_json on their elements
- json methods should not modify options argument

[#5374 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-09-07 11:33:10 -07:00
James Miller
4b07bc8475 to_json => as_json 2010-08-25 15:23:21 -07:00
Santiago Pastorino
b451de0d6d Deletes trailing whitespaces (over text files only find * -type f -exec sed 's/[ \t]*$//' -i {} \;) 2010-08-14 04:12:33 -03:00
Neeraj Singh
589e6977d7 adding documentation to ActiveSupport::Concern ht:strictly typed for an awesome example
some minor documentation changes
2010-08-04 17:03:03 -04:00
Rizwan Reza
2572af11ce Revised and added headings. 2010-06-14 13:49:01 +04:30
Mikel Lindsaar
a07d0f8786 Full update on ActiveModel documentation 2010-02-01 10:08:20 +11:00
Joshua Peek
c6bc8e6626 Break up concerns for choosing what attributes should be serialized and the actual serializer 2009-08-13 22:27:36 -05:00