Dan Gebhardt
506e2ac9ad
clean up lazy loading of serialization support for ActiveRecord::Base and ActionController::Base
2012-09-20 14:23:59 -04: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
Ray Cohen
424dacb457
scope option to render takes precedence over serialization_scope
2012-07-28 21:06:15 -04:00
Ray Cohen
1e7c69c729
Test for having scope option to render override the controller's serialization scope
2012-07-28 19:05:45 -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
ef7d475912
Merge pull request #94 from teeparham/array-serializer-root
...
Add root option to ArraySerializer
2012-07-21 00:38:18 -07: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
Tee Parham
84c7cfa988
fix test for custom serializer, add test for :each_serializer
2012-07-14 22:03:14 -06:00
Tee Parham
0832e42917
add class attribute :root to ArraySerializer
...
You can now set the default behavior for Array serialization in a
single place
2012-07-14 21:44:23 -06: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
José Valim
d6a68ed14f
Merge pull request #85 from pushcx/master
...
Allow setting :each_serializer in 'render :json' calls
2012-07-14 04:05:40 -07:00
Bradley Priest
7eb2b90b7c
Automatically include ArraySerializer in ActiveRecord::Relation
...
fixes #81
2012-07-10 10:17:54 +08: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
Andy Lindeman
47850677e9
Allows serialization_scope to be disabled with serialization_scope nil
2012-06-05 12:37:09 -04:00
Yehuda Katz
7afac9cd5c
Fix the tests
2012-06-05 10:18:05 +02: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
Yehuda Katz
3cb74887df
Merge pull request #65 from teeparham/array-root
...
use :root option in render :json
2012-06-05 00:31:13 -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
Tee Parham
9962069ae9
delete identical test
2012-05-30 10:55:35 -06:00
Tee Parham
dd00e218b1
use :root option in render :json
...
ArraySerializer can now render arrays with no root
2012-05-18 12:45:43 -06:00
José Valim
5beecd5947
Fix the build on 1.8.7 :trollface:
2012-05-17 19:28:15 +02:00
José Valim
37d894f94e
Fix build the correct way, ensure new apps work, closes #63
2012-05-17 19:18:01 +02: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
Yehuda Katz
0f1ec7a3cf
Add support for customizing fields
2012-05-16 18:13:59 -07:00
James A. Rosen
4c17a22207
add ActiveSupport.on_load announcement
2012-05-16 15:31:32 -07:00
tomhuda
33d4842dcd
Prep for 0.5.0
2012-05-16 14:17:10 -07:00
ctide
f17e4cde39
Add a :root option to associations, which enables you to define what the root level key will be for the associated objects.
2012-02-22 19:35:10 -08:00
Carl Lerche
4e8a2af1ec
Allow passing in the serializer class from the render method
2012-01-20 12:17:37 -08:00
Yehuda Katz
55647286da
Make it possible to supply default serializer
...
options in a controller.
2012-01-11 21:30:10 -07:00
Yehuda Katz
671fc14888
remove scope as a separate concept and pass it in
...
as an option.
2012-01-11 21:16:02 -07:00
Yehuda Katz
4ad9c64e46
Allow serializers to receive instructions to
...
explicitly include or exclude specific lists of
associations.
2012-01-11 20:56:36 -07:00
Yehuda Katz
cb316b00f7
Write more tests
2012-01-11 20:28:07 -07:00
Yehuda Katz
2bae9363c7
Test custom embed options per association
2012-01-11 20:21:29 -07:00
Yehuda Katz
d2c88c9dd2
Clean up pending tests
2012-01-11 20:09:28 -07:00
Yehuda Katz
d42634a1d2
Remove dead code.
2012-01-11 15:54:41 -07:00
Yehuda Katz
b22eebf569
More refactoring:
...
* Changed associations to be classes
* remove @hash and always use @options[:hash]
* pass serializer options down to child serializers
2012-01-11 15:28:49 -07:00
Yehuda Katz
89103f1e74
Test that has_one works.
2012-01-11 13:07:43 -07:00
Yehuda Katz
72b8213bee
If an existing association exists, use it to
...
get the value if none was provided.
2012-01-11 13:06:19 -07:00
Yehuda Katz
dd0b56c748
HasOne associations work
2012-01-11 12:26:49 -07:00
Yehuda Katz
f9d0259340
Start cleaning up serializers to support
...
include/exclude functionality.
This process involves building a few lower-level
primitives so not as much logic is hardcoded in
monolithic helper methods.
2012-01-11 12:18:18 -07:00
Yehuda Katz
ab1a4074ba
Revert polymorphism
2012-01-11 11:13:32 -07:00
Yehuda Katz
a8760fa854
Add pry
2012-01-10 15:16:00 -07:00
Yehuda Katz
4965558d27
with ember :ids, :include => true, has_one
...
associations should include plural versions at
the root, not singular ones.
2012-01-10 15:16:00 -07:00
José Valim
1470e3a3f4
Merge pull request #24 from Adman65/polymorphic-associations
...
Polymorphic associations
2012-01-03 03:40:56 -08:00
adman65
09bb41fbdb
Add test cases for nil polymorphic associations
2012-01-03 13:37:39 +02:00
Yehuda Katz
87d2d77ac8
In a controller, the current controller name should be the default root for collections
2012-01-01 16:01:59 -08:00
Yehuda Katz
e23553be23
The Array serializer should not make a child root for every item in the Array
2011-12-29 18:13:25 -08:00
adman65
da0c33f53c
Improve polymorphic associations
2011-12-21 20:25:40 +02:00
José Valim
b9d56a5168
Fix constant lookup when serializer is not available.
2011-12-21 09:11:04 +01:00
José Valim
cc5f102e2d
Remove implicit constant lookup in serializers in favor active_model_serializer API.
2011-12-21 08:48:29 +01:00
José Valim
97ff4d28e6
Allow as_json(true) to be given.
2011-12-21 08:17:22 +01:00
adman65
c8c8246e24
Pull in upstream
2011-12-21 00:00:09 +02:00
Yehuda Katz
df9ad0ef11
Improve serializers:
...
* Many nested levels of associations can now insert
their information alongside the original when
embed :ids, :include => true is true
* Add support for passing options to serializers
* Fix Array serializers so they don't try to insert
roots for each child object and so they can be
provided a root.
* TODO: Array serializers should require a root
* TODO: Make merging associations at the root more
efficient if possible
2011-12-20 00:03:29 -08:00
Yehuda Katz
8bdb7da272
Fix compatibility mistakes with ActiveRecord
2011-12-19 23:07:55 -08:00
Adman65
1e32090477
Serialize polymorphic id like a composite FK
2011-12-12 14:41:34 +01:00
Adman65
638614ffde
Move polymorphic type into the serializable_hash
2011-12-12 14:33:18 +01:00
Adman65
9fa716e452
Fixes #12
2011-12-12 13:13:38 +01:00
Adman65
2c240cf2e0
Implicit detection for has_many serializer
2011-12-09 16:16:09 +01:00
Yehuda Katz
09ddc79ce0
Better tests for embeds
2011-12-07 15:12:56 -08:00
Yehuda Katz
57ef67dcb4
Allow attribute aliasing
2011-12-07 14:35:07 -08:00
Yehuda Katz
7dd3bdaca9
We can't just piggyback on serialization because it may already be included at this point.
2011-12-07 12:25:11 -08:00
Yehuda Katz
ca7786c2e0
Rename :as to :key, as it's confusing
2011-12-07 12:16:22 -08:00
Yehuda Katz
0f4b61fbcf
Provide a schema for a serializer
2011-12-07 11:56:27 -08:00
Adman65
498c780a8f
Closes #4
2011-12-06 15:52:28 +02:00
Adman65
73ecb94d24
Remove railtie
2011-12-02 00:27:20 +02:00
Adman65
fffce85c5d
Remove Rails dependency
...
Move configuration into a Railtie.
Only dependency is now activemodel
2011-12-01 19:10:56 +02:00
José Valim
5a230e8e66
Added tests.
2011-12-01 08:19:14 +01:00