Commit Graph

11 Commits

Author SHA1 Message Date
Yohan Robert
d0de53cbb2 Fix namespace lookup for collections and has_many (#1973) 2016-11-15 08:35:58 -05:00
Benjamin Fleischer
6c6e45b23f Replace fail/rescue CollectionSerializer::NoSerializerError with throw/catch :no_serializer (#1767) 2016-09-26 10:18:27 -04:00
Lee Richmond
19b5abf66e Disable pagination links via config 2016-09-06 15:06:54 -04:00
Benjamin Fleischer
7254d34c90 Move Serializer#serialize into Serializer#serializable_hash 2016-06-05 23:33:37 -05:00
Benjamin Fleischer
516e7da8ff Move serialization logic into Serializer and CollectionSerializer 2016-06-04 14:59:51 -05:00
Benjamin Fleischer
a74d174420 Include Serializer._type in collection serializer json_key cascade 2016-03-27 10:55:31 -05:00
Roman Kapitonov
2dd0c33461 [FIX] Fetch json key from item serializer if empty collection is passed to collection serializer and each_searializer is specified. 2016-03-27 10:52:25 -05:00
Benjamin Fleischer
68d5233b31 Address rubocop warnings 2016-03-08 22:32:34 +01:00
Benjamin Fleischer
3d986377b6 Collapse JSON API success/failure documents in one adapter
Idea per remear (Ben Mills) in the slack:
https://amserializers.slack.com/archives/general/p1455140474000171

remear:

    just so i understand, the adapter in `render json: resource, status: 422, adapter: 'json_api/error',
    serializer: ActiveModel::Serializer::ErrorSerializer` is a different one than, say what i’ve
    specified in a base serializer with `ActiveModel::Serializer.config.adapter = :json_api`. correct?

    and a followup question of, why not same adapter but different serializer?

me:

   With the way the code is written now, it might be possible to not require a special jsonapi adapter.
   However, the behavior is pretty different from the jsonapi adapter.

   this first draft of the PR had it automatically set the adapter if there were errors.  since that
   requires more discussion, I took a step back and made it explicit for this PR

   If I were to re-use the json api adapter and remove the error one, it think the serializable hash
   method would look like

   ```
   def serializable_hash(options = nil)
     return { errors: JsonApi::Error.collection_errors } if serializer.is_a?(ErrorsSerializer)
     return { errors: JsonApi::Error.resource_errors(serializer) } if serializer.is_a?(ErrorSerializer)
     options ||= {}
   ```

   I suppose it could be something more duckish like

   ```
   def serializable_hash(options = nil)
     if serializer.errors? # object.errors.any? || object.any? {|o| o.errors.any? }
       JsonApi::Error.new(serializer).serializable_hash
     else
       # etc
   ```
2016-03-06 12:03:17 -06:00
Ben Woosley
251e33a0a1 Don't pluralize the CollectionSerializer#root for #json_key
One of three constituents is used to provide the
CollectionSerializer's #json_key:

1) the :root option - controlled by the caller
2) the #name of the first resource serializer - the root or
   underscored model name
3) the underscored #name of the resources object - generally
   equivalent to the underscored model name of #2

Of the three, only the latter 2 are out of the callers control, and
only the latter two are expected to be singular by default. Not
pluralizing the root gives the caller additional flexibility in
defining the desired root, whether conventionally plural,
unconventionally plural (e.g. objects_received:) or singular.
2016-01-12 09:32:43 -08:00
Benjamin Fleischer
2c8b9b796d Rename ArraySerializer to CollectionSerializer for clarity 2015-10-21 16:53:26 -05:00