Commit Graph

441 Commits

Author SHA1 Message Date
Pol Miro
e8b983490e Separate associations into multiple files 2014-08-25 23:32:09 -07:00
Theodore Konukhov
26c0847563 - If a controller is in a namespace, serializer will be looked up in this namespace first.
- Serializers for associations will be looked up in a parent serializer's namespace first too.
- "Prefix" option for different versions of associations serializers. Example: has_many :users, as: :short -> ShortUserSerializer

TODO: tests, config option for enabling namespace lookup
2014-08-24 15:57:24 +02:00
Radan Skoric
ddfd8d2c11 embed_in_root works even if serializer is invoked through another serializers' association which itself does not have embed_in_root set 2014-08-23 18:21:24 +02:00
Steve Klabnik
2fec5111ef Bump version to 0.9.0 2014-08-22 16:17:46 -04:00
Steve Klabnik
ae7959b76e Merge pull request #512 from TimPetricola/fix-options-access
Custom options are accessible in serializer
2014-08-22 16:15:41 -04:00
Steve Klabnik
74625f778b Merge pull request #594 from bolshakov/feature/custom_array_serializer
Support custom array serializer
2014-08-22 15:28:26 -04:00
Steve Klabnik
e9378cc9ab Merge pull request #595 from bolshakov/feature/array_serializer_options
Array serializer pass except and only options to item serializers
2014-08-22 15:26:17 -04:00
Steve Klabnik
92f1db0137 Merge pull request #596 from bolshakov/feature/instumentation
Test::Unit assert_serializer implemented
2014-08-22 15:25:52 -04:00
Tema Bolshakov
699b378984 remove nested case 2014-08-20 12:35:23 +04:00
Tema Bolshakov
c5d9d97f26 Assert with serializer class 2014-08-20 12:34:34 +04:00
Tema Bolshakov and Dmitry Myaskovskiy
aa66592a80 Update docs 2014-08-18 18:24:07 +04:00
Arthur Nogueira Neves
9fb343b5fb Merge pull request #591 from donbobka/feature/fix_format_keys_for_array_wo_root
Feature/fix format keys for array wo root
2014-08-18 10:21:37 -04:00
Tema Bolshakov and Dmitry Myaskovskiy
eaedcefa4e Test::Unit assert_serializer implemented
So you can assert specific serializer to be used.
2014-08-18 18:04:51 +04:00
Tema Bolshakov
e3ab34dd74 Array serializer pass except and only options to item serializers 2014-08-18 14:21:08 +04:00
Tema Bolshakov
c389ae2207 Support customer array serializer 2014-08-18 12:37:01 +04:00
Vladimir Lyzo
adcea6aaf0 Fix failing test: option format_key with root option 2014-08-15 16:21:40 +04:00
Jean Boussier
0d31e72d22 Allow users to opt-out from the ActionController extensions 2014-08-14 10:28:36 -04:00
Stanley Stuart
e650863c6d fix tests from rebasing master for embed_namespace 2014-08-13 11:38:01 -05:00
Paul Henry
76263865a7 fix uninitialized instance variable warning
Ruby warns that `@only` and `@except` are not initialized because if they are not passed in, they are never assigned.

Remove circular require in array_serializer
2014-08-02 14:05:37 -07:00
Tim Petricola
14b1df5c36 Custom options are accessible in serializer (via :context) 2014-07-28 13:10:02 -04:00
Steve Klabnik
045ba2a48c Merge pull request #534 from kylefritz/master
Support lowerCamel key format
2014-07-28 12:43:36 -04:00
Steve Klabnik
723049e28f Merge pull request #493 from shakirshakiel/master
fixing sideloading of nested associations
2014-07-28 12:34:17 -04:00
Kyle Fritz
76c8de7b9f root key format 2014-04-14 13:45:12 -04:00
Kyle Fritz
00c54baae3 Support lowerCamel key format 2014-03-30 12:31:21 -04:00
Wojtek Mach
2e31a14125 Add :only/:except options 2014-03-12 16:55:08 -03:00
Ken Ip
8ca4d4fcd6 HasOne nil object should return [] under embedded key.
Ensure that @wrap_in_array is always respected when set to true even
when associated object is nil.
2014-03-10 16:42:04 -03:00
Santiago Pastorino
d985e6424c Merge pull request #462 from fab/master
Generator now properly detects ApplicationSerializer
2014-02-04 10:05:03 -08:00
Fab Mackojc
a49e04a6f2 Generator now properly detects ApplicationSerializer 2014-02-01 21:37:13 +11:00
Shakir Shakiel
9ae5142775 fixing sideloading of nested associations 2014-01-22 00:07:28 +05:30
Adrian Mugnolo and Santiago Pastorino
cec7980208 Don't embed empty associations in root 2014-01-09 15:45:20 -02:00
Santiago Pastorino
3e510c829b Don't concat to nil objects 2014-01-09 15:35:29 -02:00
Jorge Bejar
df481b2b35 Don't memoize association serializer 2014-01-09 15:30:51 -02:00
Santiago Pastorino
de78df509a Version = 0.9.0.alpha1 2014-01-07 15:28:23 -02:00
Santiago Pastorino
ed9a5288f9 Revert "Merge branch 'context'"
This reverts commit 1bd8180a94, reversing
changes made to 9bb32331f4.
2014-01-07 15:02:09 -02:00
Adrian Mugnolo and Santiago Pastorino
dc32b5fc1b Extract context build to a method 2014-01-06 15:50:53 -02:00
Adrian Mugnolo and Santiago Pastorino
0d8ef2b165 Nest scope under context option 2014-01-06 15:50:30 -02:00
Santiago Pastorino
8bd2542ed2 Allow to pass context around serializers 2014-01-06 12:22:16 -02:00
Santiago Pastorino
78245b07bc Move the default value to the options param 2014-01-03 20:02:43 -02:00
Santiago Pastorino
5fa4002039 Allow only to pass scope to associations
Closes #483
2014-01-03 19:48:01 -02:00
Santiago Pastorino
60fc55021c Revert "Allow to pass options to associations"
This reverts commit c8cfe94f29.
2014-01-03 19:44:40 -02:00
Santiago Pastorino
c8cfe94f29 Allow to pass options to associations
Closes #331
2014-01-02 19:56:08 -02:00
Santiago Pastorino
67c550f2ee Serialize embedding in root deeply nested associations
Closes #444
2014-01-02 18:34:11 -02:00
Santiago Pastorino and Adrian Mugnolo
8fa252b4fd Make sure generator hooks get run
Use Rails::Engine#load_generators instead of require +
Rails::Generators::configure!.
2013-12-30 12:03:51 -02:00
Adrian Mugnolo
1c9ab8fd24 Drop reference to self 2013-12-30 10:57:39 -02:00
Adrian Mugnolo and Santiago Pastorino
0f4547eb77 Rename method to serializable_object 2013-12-17 16:13:50 -02:00
Adrian Mugnolo and Santiago Pastorino
f14f931957 Clean up HasOne array wrapping logic
Introduce private _wrap_in_array option for now.
2013-12-17 15:42:35 -02:00
Adrian Mugnolo and Santiago Pastorino
28fbb62ec4 Avoid unneeded logic 2013-12-17 13:14:39 -02:00
Santiago Pastorino
80d9fb56d2 Merge pull request #452 from plexus/has_one_each_serializer_fix
Using a HasOne association twice raises an exception (Undefined method `map')
2013-12-16 17:49:26 -08:00
Adrian Mugnolo and Santiago Pastorino
700e6b83c1 Serializers now inherit root 2013-12-16 17:55:50 -02:00
Adrian Mugnolo and Santiago Pastorino
115de49004 Remove explicit reference to self 2013-12-16 17:27:49 -02:00
Santiago Pastorino
adee76181f Merge pull request #468 from stas/attrs_and_assoc_inheritance
Serializers now inherit attributes and associations.
2013-12-16 11:14:16 -08:00
Santiago Pastorino
5c00ce0443 Merge pull request #451 from plexus/embed_in_root_merge
embed_in_root only returns the associated objects of a single instance
2013-12-16 10:39:53 -08:00
Stas SUȘCOV
0febd8f628 Serializers now inherit attributes and associations. 2013-12-11 17:59:32 +02:00
Jason Truluck
a110df6caf Add @options back into serializers to maintain the functionality of render :json as noted in the docs
This functionality used to exist in v0.8.1. This adds the ability to
pass other options that will be usable in the serializer via the
options accessor.

This works by adding an attr_accessor for options so it is available
and is set by the remaining options in the provided options hash during
initialization.
2013-11-12 12:57:31 -05:00
Arne Brasseur
8c3866532a Fixes a bug in the HasOne association where serializing twice in a row causes
an exception.
2013-11-11 15:30:46 +01:00
Arne Brasseur
1db96ec7a9 When using embed: :ids ; embed_in_root: true, and serializing multiple objects,
only the associated objects of the last object in the collection will actually
show up in the serialized data.

For example, if you serialize a collection of two posts, each containing one or
more comments, only the comments of the last post show up. The reason is a
Hash#merge wich overwrites the array rather than appending to it.

This commit fixes this by merging the collection arrays, rather than the top-level
hashes.
2013-11-11 14:30:34 +01:00
Todd Bealmear
e0a564aa68 Fixed Rails 3 compatibility. 2013-11-04 17:45:36 -08:00
Todd Bealmear
f10f72c763 Fixed Rails 4 Controller Scaffold Generator. 2013-11-04 17:31:19 -08:00
Santiago Pastorino
99677c0c58 Pass scope through to associations via @lastobelus
Closes #433
2013-11-04 10:48:19 -02:00
Santiago Pastorino
60b5901af8 Don't treat has_one associations embed objects as an array
Closes #442

Thanks @arrtchiu for reporing and giving a test case
2013-11-04 10:09:29 -02:00
Santiago Pastorino
ef1ec65ae7 Make DefaultSerializer include AM::Serializable so embedded_in_root_associations is always defined also there 2013-11-01 22:35:56 -02:00
Santiago Pastorino
882dbafa7e embedded_in_root_associations is always defined 2013-11-01 21:37:49 -02:00
Santiago Pastorino
66f9256534 Embed objects should return singular and not wrap in array
Closes #437
2013-11-01 14:22:52 -02:00
Santiago Pastorino
d3d6c98148 Make ArraySerializer reuse Serializer embedded_in_root_associations code 2013-10-31 17:28:39 -02:00
Santiago Pastorino
5598bb0f79 Make Associations in root work with ArraySerializer
Closes #414
2013-10-31 17:27:36 -02:00
Santiago Pastorino
85a9c185ca Move responsibility of setting a serializer class and building a serializer for an association to the association class 2013-10-31 16:45:00 -02:00
Santiago Pastorino
616938dc63 Improve build_json_serializer readability a bit 2013-10-30 23:37:36 -02:00
Santiago Pastorino
4d4b820cbe has_one returns arrays with roots pluralized 2013-10-30 15:26:13 -02:00
Santiago Pastorino
1eea008336 Split root construction and serialization logic 2013-10-29 19:39:27 -02:00
Santiago Pastorino
49ab359a34 Support passing a custom ArraySerializer for has_many associations
Thanks @phoet

Closes #316
2013-10-29 00:26:45 -02:00
Santiago Pastorino
d5308b4d0b Remove old unneeded code 2013-10-26 03:01:17 -02:00
Santiago Pastorino
1eb09476ef Revert "Merge pull request #422 from marclove/reduce-serializer-code-complexity"
This reverts commit 449849516b, reversing
changes made to e103569c22.

Conflicts:
	lib/active_model/serializer.rb
2013-10-26 01:19:15 -02:00
Arthur Neves
303ac21428 Small refactoring 2013-10-25 19:58:06 -04:00
Marc Love
5ac6e626b5 Reduce complexity and duplication; make accessor definition more explicit 2013-10-25 15:33:24 -07:00
Santiago Pastorino
439643ba5a Fix the stupid previous commit 2013-10-24 19:23:50 -02:00
Santiago Pastorino
b44e1af5dd Move synchronize to setup method and make CONFIG private 2013-10-24 17:42:20 -02:00
Santiago Pastorino
dc33dac56b This is not being used 2013-10-24 16:57:42 -02:00
Santiago Pastorino
dfdc292e35 Align = 2013-10-24 16:32:18 -02:00
Arthur Neves
860acad9af s/side_load/embed_in_root 2013-10-24 14:12:02 -04:00
Santiago Pastorino
2b70503896 Add ActiveModel::SerializerSupport 2013-10-24 16:09:00 -02:00
Santiago Pastorino
cef6f85f44 Deprecate include in favor of side_load 2013-10-24 15:09:26 -02:00
Santiago Pastorino
48db253765 embed_in_root is now side_load 2013-10-24 14:57:41 -02:00
Santiago Pastorino
5c6541145a Allow to embed nothing but still side loading
Closes #361, #399, #401
2013-10-24 13:24:49 -02:00
Santiago Pastorino
df5ef33ae6 Allow to turn off ams
Closes #378

You can define now

```
def default_serializer_options
  { serializer: false }
end
```
2013-10-23 20:34:34 -02:00
Łukasz Strzałkowski
d46584af40 Wrap config's data hash in mutex 2013-10-21 20:27:01 +00:00
Arthur Neves
05ec509e1c Use ActiveSupport::Deprecation.warn instead of warn 2013-10-21 15:02:39 -04:00
Santiago Pastorino
7dcef9f0f5 Rename Settings to Config and use accessors to configure things 2013-10-21 16:23:35 -02:00
Arthur Neves
84801301b9 Add deprecation message to .embed method 2013-10-21 13:08:07 -04:00
Arthur Neves
41f1855056 Add accessors to settings class 2013-10-21 13:05:39 -04:00
Santiago Pastorino
4ab16381bd Bump version to 0.9.0.pre 2013-10-18 17:49:22 -02:00
Santiago Pastorino
73774649e3 Implement Generators 2013-10-18 17:49:21 -02:00
Santiago Pastorino
91f9317713 There's no need to define read_attribute_for_serialization in the Serializer class 2013-10-18 17:49:21 -02:00
Santiago Pastorino
b9a6dfac2f Do not call send on associated objects, do it through elem.read_attribute_for_serialization 2013-10-18 17:49:21 -02:00
Santiago Pastorino
4b91d0e5ec embed :objects is the default
A commit with an integration test that covers this functionality is
coming after this one
2013-10-18 17:49:20 -02:00
Santiago Pastorino
4f70dc2091 has_one serialized objects shouldn't be wrapped in an array and it's key is singular 2013-10-18 17:49:20 -02:00
Santiago Pastorino
dbf512c14c Make embed nil ids work 2013-10-18 17:49:20 -02:00
Santiago Pastorino
cad8fafa60 Optimize serializer_for for Ruby >= 2.0 2013-10-18 17:49:20 -02:00
Santiago Pastorino
841f3b8181 Add filter to allow users implement filter method to include/exclude attributes and relations 2013-10-18 17:49:20 -02:00
Santiago Pastorino
f6ea07dd22 Do not convert attrs to String until needed 2013-10-18 17:49:20 -02:00
Santiago Pastorino
daa9304398 Do not convert root and meta_key to Strings 2013-10-18 17:49:20 -02:00