Commit Graph

79 Commits

Author SHA1 Message Date
Steve Klabnik
e76a16486f Merge pull request #170 from FundingGates/master
Support optional types for computed attributes
2013-03-08 09:11:29 -08:00
Steve Klabnik
06c65871a8 Merge pull request #213 from michihuber/fix_rendering_nil_with_custom_serializer
Fix rendering nil with custom serializer
2013-03-05 15:54:51 -08:00
Steve Klabnik
d638e21c8c Merge pull request #180 from fellix/fix-remove-root-globally
Fix global ``` self.root = false ```
2013-03-05 15:48:08 -08:00
Ismael Abreu
2d2094b588 changes to be able to specify multiple attributes with keys 2013-03-05 02:45:22 +00:00
Michi Huber
c7a420d295 Don't fail if object is nil, render null 2013-02-26 11:17:28 +01:00
Rafael Felix
82951c1f8a Fix global `` self.root = false ``
Using the on_load hook does not change the defined root on
Serializer#inherited.

Related to #179
2013-01-24 09:13:41 -02:00
Steve Klabnik
e3bfd07ac4 Merge pull request #161 from kevins90/fix_attr_name_as_serializer_underscored_prefix
Fix serialization of attribute whose name matches the serializer prefix underscored
2013-01-05 14:09:15 -08:00
Dan Gebhardt
3b1d2faf51 Append an _id or _ids suffix to associations' keys. Embed objects in root according to their serializers' names.
An `_id` suffix will be appended to the name of HasOne associations, while `_ids` will be appended to the singularized name of HasMany associations. Association keys can still be overridden with the `key` option.

Furthermore, objects embedded in the root are now by default named according to their serializer, instead of the key used for their associations.
2012-12-21 15:14:50 -05:00
Matt Rogish
72652ce37e Adding info to the readme on how to specify the type, adding an additional
test to cover a computed property without a type
2012-12-11 10:33:17 -05:00
Matt Rogish
25c564bd6f Adding optional type for attributes 2012-12-10 19:58:58 -05:00
Steve Klabnik
6780cd3df5 Merge pull request #138 from tchak/meta
Meta object
2012-12-10 10:48:39 -08:00
Kevin Tham
14a35ab2f8 Remove unneeded method aliasing of attribute reader: object, with the underscored class name of serializer, to fix issue where a model's attribute name matches that of the underscored prefix of the serializer 2012-11-25 00:17:17 -08:00
Jo Liss
2fc083a1fe Merge pull request #117 from joliss/computed-attributes
Make schema not crash on computed attributes & associations
2012-11-22 08:31:18 -08:00
tchak
a71698d5bb Add support for meta key
Test for meta_key serialization
2012-11-22 13:44:59 +01:00
Tee Parham
2cb7a41780 move ArraySerializer tests into separate file 2012-11-20 10:58:16 -07:00
Tee Parham
f47a10cadc move test fakes to separate file 2012-11-20 10:44:23 -07:00
Samnang Chhun
96ce310595 Add alias_method ActiveModel::Serializer.root= to be consistency with ActiveModel::ArraySerializer 2012-11-20 00:29:00 +07:00
Jo Liss
538b0c0916 Make schema not crash on computed associations
We pick nil here as well.
2012-10-31 20:07:08 +01:00
Jo Liss
6281a9149e Make schema not crash on computed attributes
We do not know the type for computed attributes, so we pick nil.

Perhaps at some point we might add a :type option for attributes (or
not), but in any case it's important to not crash when there are
computed attributes.
2012-10-31 20:07:08 +01:00
Jo Liss
ee3cec3d0c When objects are sideloaded multiple times, serialize them only once
To achieve this, we make the following change when sideloading: Instead
of serializing associations and discarding duplicate *hashes*, we
memorize the *objects* (records) that we have already serialized, and
only serialize those that are new.

This change is mostly transparent, and brings down serialization time
from 3.1 seconds to 1.0 seconds on my set of sample data.

There is one change in the behavior: If you sideload the same object
multiple times, and it yields different hashes, like so:

    embed :ids, include: true
    has_many :comments
    has_many :recent_comments, root: comments, serializer: CommentShortSerializer

then previously, it would be included multiple times, whereas now, the
first hash wins. (I haven't actually tested this.) I don't know that
either option is preferable. It's not covered by the test suite, and I
think it's an edge case that is OK to ignore entirely.
2012-10-29 23:15:32 +01:00
Dan Gebhardt
42221a6140 define include_XXX? methods, which can be overridden to conditionally include attributes and associations 2012-08-29 09:26:41 -04:00
Dan Gebhardt
68dc57eb73 simplified the API for include_associations!() to make conditional includes cleaner 2012-08-29 07:42:23 -04:00
twinturbo
38859d1f3d Easier to work with polymorphic interface 2012-08-25 17:39:39 +02:00
Alex Kwiatkowski & Will Bagby
754aa295ba Return empty hash when url_options not provided 2012-08-07 12:56:58 -04:00
José Valim
b813646076 assert_include is not available before 1.9 2012-07-21 10:01:27 +02:00
José Valim
e886f597c7 Sets are not ordered, do not depend on the order 2012-07-21 09:48:12 +02:00
José Valim
62484e758c Merge pull request #95 from twinturbo/set-serializer
Close #90
2012-07-21 00:37:31 -07:00
twinturbo
6f3b250dc9 Don't include empty polymoprhic associations
Take this serializer:

class TodoSerializer < ActiveModel::Serializer
  root :todo, :include => true
  has_one :reference, :polymorphic => true
end

A nil reference would generate this JSON:

{
  "todo": { "reference": null },
  "nil_classes": []
}

This commit prevents the `nil_classes` key from being added when
serializing and including nil polymoprhic associations.
2012-07-16 15:08:01 +02:00
twinturbo
486d282922 Raise error when associations cannot be included
include! only works when the source serializer has a root set. The
as_json method sets up some state for the include! method. If a child
association has associations with `:include => true` or `root foo,
:include => true` would cause an undefined method error for `NilClass`.
This is entirely unhelpful for the end user.

This commit raise an error when this situation occurs. It makes it clear
that it's not a problem with AMS but the serialization graph.
2012-07-16 14:18:58 +02:00
twinturbo
5111615ac1 Actually test set serialization 2012-07-15 13:42:29 +02:00
Bradley Priest
f85c624d02 Fix travis 2012-07-15 18:50:47 +08:00
twinturbo
7072e79787 Close #90 2012-07-15 12:18:41 +02:00
twinturbo
cbd7d7d385 Add test for nested included polymoprhic associations 2012-07-15 11:49:36 +02:00
twinturbo
c4e5cd547b Add test for complex polymorphic associations 2012-07-15 11:49:36 +02:00
twinturbo
9f20fe8b36 Test passes 2012-07-15 11:49:36 +02:00
twinturbo
3ca1621011 Add failing test for polymorphic with include 2012-07-15 11:49:36 +02:00
twinturbo
7e96856b87 Support serialize polymorphic id 2012-07-15 11:49:36 +02:00
twinturbo
32f8779114 Basic rooted polymorphism 2012-07-15 11:49:36 +02:00
José Valim
56824f055b Update master 2012-07-14 18:17:36 +03:00
twinturbo
7936e3efba Add "scope" method 2012-07-14 14:54:23 +02:00
José Valim
3e87c6414d Merge pull request #92 from twinturbo/query-attributes
Close #86
2012-07-14 04:16:07 -07:00
twinturbo
2b9cd97436 Close #86 2012-07-14 13:12:26 +02:00
Peter Harkins
1c820a9ba7 Allow setting the serializer for ArraySerializer. 2012-06-21 11:12:13 -05:00
Tee Parham
c898e3daf9 remove unncessary is_a?(Hash) check 2012-06-12 10:38:32 -07:00
Yehuda Katz
6e2554d741 Merge pull request #62 from highgroove/cleanup_scope_instance_variables
Remove left over references to scope instance variable
2012-06-05 00:32:23 -07:00
Tee Parham
f35a2261d2 support different serializations in ArraySerializer
ArraySerializer can serialize arrays of Hash, ActiveModel::Serializer,
or any PORO that responds to :as_json

Each item in the array should not include its type as a root element,
since normal arrays do not do this. If you want "typed" collections,
don't use an Array.
2012-05-30 14:52:52 -06:00
Tee Parham
00db4dd6db rename test methods so tests run
incidentally test_array_serializer_with_root fails
2012-05-30 11:14:49 -06:00
vanstee
81fddb55d3 Remove left over references to scope instance variable 2012-05-16 22:54:26 -04:00
Yehuda Katz
56b61b1532 Add URL to serializers (closes #61)
Thanks so much to @vanstee for the initial
implementation!
2012-05-16 18:35:30 -07:00
Yehuda Katz
5f4f6a3483 Merged on_load 2012-05-16 18:17:21 -07:00