Commit Graph

158 Commits

Author SHA1 Message Date
Benjamin Fleischer
516e7da8ff Move serialization logic into Serializer and CollectionSerializer 2016-06-04 14:59:51 -05:00
Benjamin Fleischer
41575e36f7 Moving Attributes#serializable_hash_for_single_resource to Serializer 2016-06-04 14:59:51 -05:00
Lucas Hosseini
f48fd2a327 Extract IncludeTree. (#1685) 2016-05-28 10:07:11 -04:00
Benjamin Fleischer
929a5d0a51 Restrict serializable_hash to accepted options, only for tests 2016-04-13 00:40:57 -05:00
Benjamin Fleischer
6370e5c72a Fix read_attribute_for_serialization not seeing parent serializer methods
Fixes #1653, #1658, #1660

Define "scope_name" on instance singleton, not all instances
2016-04-04 12:29:26 -05:00
Benjamin Fleischer
a065bc28d1 Fix serialization scope options 2016-04-01 05:43:46 -05:00
Benjamin Fleischer
ec5dc497b0 Handle render.ams with nil serializer or adapter 2016-03-28 21:33:23 -05:00
Benjamin Fleischer
a74d174420 Include Serializer._type in collection serializer json_key cascade 2016-03-27 10:55:31 -05:00
Benjamin Fleischer
eda8ff1737 Move serializer caching from adapter 2016-03-13 19:57:59 -05:00
Benjamin Fleischer
b169ed387b Make serializers serializable, step 1. 2016-03-13 00:26:15 -06:00
Benjamin Fleischer
85658c0230 Add better serialization_scope tests; uncover bug 2016-03-12 19:59:43 -06:00
Benjamin Fleischer
6b4c8df6fb Clean up test deprecation warnings 2016-03-06 23:35:22 -06:00
Yohan Robert
dd94fe2163 Follow up to #1535
- The removed classes and modules were added back with deprecation
  warning and deprecation test were added for them.
- One test was renamed because it contained `__`.
- Some tests were refactored.
- The ActiveModelSerializers::Deserialization module is now called
  Adapter instead of ActiveModelSerializers::Adapter.
- The changelog was added for #1535
2016-03-06 23:15:39 -06: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
Benjamin Fleischer
96107c56aa Require explicit adapter/serializer to render JSON API errors
- Separate collection errors from resource errors in adapter
- Refactor to ErrorsSerializer; first-class json error methods
- DOCS
- Rails 4.0 requires assert exact exception class, boo
2016-03-06 12:03:17 -06:00
Benjamin Fleischer
0ba944dabf RFC: Json Api Errors (WIP)
- ActiveModelSerializers::JsonPointer
- ActiveModel::Serializer::Adapter::JsonApi::Error
- ActiveModel::Serializer::Adapter::JsonApi::Error.attributes
- Fix rubocop config
2016-03-06 12:03:14 -06:00
Benjamin Fleischer
e35390623d Improve adapter test coverage per groyoh 2016-02-25 23:08:20 -06:00
Benjamin Fleischer
25c9df0b97 Merge branch 'master' into domitian-move-namespace-of-adapter-to-active-model-serializers
Conflicts:
	CHANGELOG.md
	lib/active_model/serializer/adapter/attributes.rb
	lib/active_model/serializer/adapter/cached_serializer.rb
	lib/active_model/serializer/adapter/fragment_cache.rb
	lib/active_model/serializer/adapter/json_api.rb
	lib/active_model/serializer/adapter/json_api/link.rb
	test/adapter/fragment_cache_test.rb
	test/adapter/json_api/links_test.rb
	test/adapter/json_api/resource_type_config_test.rb
2016-02-23 23:21:49 -06:00
bobba surendranath chowdary
252f9c4ae9 Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace
Changed the namespace in adapters and folder to active_model_serializers from active_model::serializer

Changed namespace of adapters in serializers and other folders

Moved adapter_for_test file to active_model_serializers folder and changed namespace of adapter inside the test file

Require ActiveSupport's string/inflections

We depend on string/inflections to define String#underscore.

Refactor JsonApi adapter to avoid redundant computations.

Update readme.md to link to v0.10.0.rc4

changed namespace of adapter folder testcases

Changed all namespaces of adapter under active_moder_serializers

Namespaced IncludeTree which is from serializer module, so needed to namespace it properly

Fixed wrong namsepacing of fieldset

namespace change in deserializer json_api

Fixed the namespace for collection serializer when used inside adapter, changed namespace for adapter to new namespace which I had forgotten previously

Modified logging test and adapter test cases to make the testcases pass

Changed the yardoc links,as old links are not taking to documentation pages,proper links for 0.10,0.9 and 0.8 in rubydoc

Rubocop errors are fixed by underscore naming unused variables

Moved the require of adapter to serializable resource

Remoeved adapter dependency inside serializer and added warning to Serializer::adapter method

Fixed frament cache test which is calling Serializer.adapter

Changed the name of lookup_adapter_from_config to configured_adapter

Changed the docs which will show the new namespace of adapters

Rubocop fix
2016-02-23 21:49:58 -06:00
Benjamin Fleischer
50950d9533 Merge branch 'beauby-resource-level-meta'
Followup concerns:
- https://github.com/rails-api/active_model_serializers/pull/1340/files#r47451387
- https://github.com/rails-api/active_model_serializers/pull/1340/files#r48116963
- https://github.com/rails-api/active_model_serializers/pull/1340#discussion_r47451387
- https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-164306882
- https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-166202978
- https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-173028896
2016-02-08 18:00:51 -06:00
bobba surendranath chowdary
68f09e59c4 Fixed a documentation error regarding adapter key constant, added tests
for SerializableResource::use_adapter?
2016-02-08 15:27:56 +05:30
Lucas Hosseini
701404f757 Clean up meta handling. 2016-01-20 01:00:14 +01:00
Lucas Hosseini
0bd5c6584f Add support for resource-level meta. 2016-01-20 00:49:13 +01:00
Lucas Hosseini
f6fe0c8aa3 Extract links and type-related methods to their own module. 2016-01-12 15:05:39 +01:00
Lucas Hosseini
fd06a8ad0d Extract caching into its own module. 2015-12-28 02:53:49 +01:00
Benjamin Fleischer
30fd9d9eb7 Merge pull request #1353 from bf4/disable_serializer_lookup
Allow users to globally opt out of automatic serializer lookup
2015-12-20 20:04:16 -06:00
Benjamin Fleischer
3e8290a923 Serializer instance methods don't change; track at class level
Per groyoh
https://github.com/rails-api/active_model_serializers/pull/1356#discussion_r46713503
2015-12-04 13:31:34 -06:00
Benjamin Fleischer
036604b149 Extract Serializer Attributes into its own file 2015-12-02 17:45:42 -06:00
Benjamin Fleischer
eceb2d5598 Refactor serializer attribute objects 2015-12-02 17:33:57 -06:00
Benjamin Fleischer
8804d758ef Remove dynamically defined instance methods 2015-12-02 17:20:22 -06:00
Benjamin Fleischer
0bf45ec2a7 Small refactor to Serializer::_attribute_mappings 2015-12-02 17:20:22 -06:00
Noah Silas
7bde7bf752 Handle conflicts between key names and serializer methods
As an example, all serializers implement `#object` as a reference to the
object being esrialized, but this was preventing adding a key to the
serialized representation with the `object` name.

Instead of having attributes directly map to methods on the serializer,
we introduce one layer of abstraction: the `_attributes_map`. This hash
maps the key names expected in the output to the names of the
implementing methods.

This simplifies some things (removing the need to maintain both
`_attributes` and `_attribute_keys`), but does add some complexity in
order to support overriding attributes by defining methods on the
serializer. It seems that with the addition of the inline-block format,
we may want to remove the usage of programatically defining methods on
the serializer for this kind of customization.
2015-12-02 17:20:22 -06:00
Lucas Hosseini
7cbef1b3b5 Add inline syntax for defining associations
Adapted from
https://github.com/rails-api/active_model_serializers/pull/1262
2015-12-02 17:20:22 -06:00
Benjamin Fleischer
6020450fe4 Allow specifying attributes with a block
Adapted from https://github.com/rails-api/active_model_serializers/pull/1262
2015-12-02 17:20:22 -06:00
Benjamin Fleischer
87d18e9c32 Map attributes to Attribute values when defined in serializer 2015-12-02 17:20:22 -06:00
Randy Stauner
90fa377040 Match file paths with spaces in caller regexp 2015-12-02 06:17:34 -07:00
Benjamin Fleischer
28394340d8 Add config.serializer_lookup_enabled that defaults true 2015-11-30 00:20:58 -06:00
Benjamin Fleischer
a9ce4fb766 Move caching initialization to Railtie
Also
- Add reference to config from ActiveModelSerializers.config
- correctly call super in FragmentCacheTest#setup
- rename test rails app from Foo to ActiveModelSerializers::RailsApplication
2015-11-25 21:56:01 -06:00
Lucas Hosseini
3804dcc238 Add support for resource-level JSON API links. 2015-11-03 23:50:16 +01:00
Lucas Hosseini
0948c4199a Compute only requested attributes. 2015-10-31 19:20:53 +01:00
Lucas Hosseini
1a42345d84 Only use subclasses of ActiveModel::Serializer during lookup. 2015-10-23 17:17:03 +02:00
Benjamin Fleischer
274cb66d34 Edits per beauby [ci skip] 2015-10-22 10:31:21 -05:00
Lucas Hosseini
63317699f3 Correct minor typos 2015-10-22 10:31:21 -05:00
Benjamin Fleischer
80e75202ea Document Serializer and FragmentCache 2015-10-22 10:31:21 -05:00
Benjamin Fleischer
2c8b9b796d Rename ArraySerializer to CollectionSerializer for clarity 2015-10-21 16:53:26 -05:00
Benjamin Fleischer
8529ea43c9 Handle no serializer source file to digest.
output warning

Closes #1176
2015-10-14 20:56:29 -05:00
L. Preston Sego III
6018ef16c4 Merge pull request #1225 from beauby/nested-serializer-lookup
Add support for nested serializers
2015-10-09 10:12:08 -04:00
Benjamin Fleischer
f52ade25aa Merge pull request #1255 from bf4/serialize_inheritable_attributes
Make more class attributes inheritable
2015-10-09 03:10:28 -05:00
Lucas Hosseini
9147469842 Extend serializer lookup to the parent serializer. 2015-10-08 18:23:54 +02:00
L. Preston Sego III
d5e6e3148a Merge pull request #1254 from bf4/remove_useless_access_modifier
Remove unnecessarily silenced warnings
2015-10-07 07:22:15 -04:00