active_model_serializers/lib/active_model/serializer
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
..
adapter/json_api Merge branch 'master' into domitian-move-namespace-of-adapter-to-active-model-serializers 2016-02-23 23:21:49 -06:00
array_serializer.rb Test ArraySerializer less rigorously on Minitest 4 2015-11-08 23:12:56 -06:00
association.rb Add support for relationship-level links and meta. 2016-01-21 02:36:54 +01:00
associations.rb Replace Field#included? with Field#excluded?. 2016-01-13 06:20:05 +01:00
attribute.rb Factor out ancestor class Field of Attribute and Reflection. 2016-01-13 06:20:04 +01:00
attributes.rb Replace Field#included? with Field#excluded?. 2016-01-13 06:20:05 +01:00
belongs_to_reflection.rb Associations refactoring 2015-07-30 11:20:29 +03:00
caching.rb Extract caching into its own module. 2015-12-28 02:53:49 +01:00
collection_reflection.rb Associations refactoring 2015-07-30 11:20:29 +03:00
collection_serializer.rb Collapse JSON API success/failure documents in one adapter 2016-03-06 12:03:17 -06:00
configuration.rb Create assert_response_schema test helper 2016-01-15 00:45:56 -06:00
error_serializer.rb Collapse JSON API success/failure documents in one adapter 2016-03-06 12:03:17 -06:00
errors_serializer.rb Collapse JSON API success/failure documents in one adapter 2016-03-06 12:03:17 -06:00
field.rb Replace Field#included? with Field#excluded?. 2016-01-13 06:20:05 +01:00
fieldset.rb Initialize fieldset. 2015-10-25 19:56:43 +01:00
has_many_reflection.rb Associations refactoring 2015-07-30 11:20:29 +03:00
has_one_reflection.rb Associations refactoring 2015-07-30 11:20:29 +03:00
include_tree.rb Add test and bugfix to include an array of string 2015-11-06 17:23:25 +01:00
links.rb Fix comment. 2016-01-13 05:41:32 +01:00
lint.rb RFC: Json Api Errors (WIP) 2016-03-06 12:03:14 -06:00
meta.rb Clean up meta handling. 2016-01-20 01:00:14 +01:00
reflection.rb Fix relationship behavior when using block 2016-02-10 21:04:37 +01:00
singular_reflection.rb Associations refactoring 2015-07-30 11:20:29 +03:00
type.rb Add symbol support for ActiveModel::Serializer.type method 2016-02-19 17:05:13 +01:00
version.rb releaseing new version RC4 2016-01-27 10:03:01 -05:00