From dd0d9c68357eadea0a9ee99f48d22d669b7e9bea Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Wed, 15 Jun 2016 10:31:33 -0500 Subject: [PATCH] Generating docs for version 0.10.0 at ref 7578a3c. --- ActionController.html | 2 +- ActionController/Serialization.html | 2 +- .../Serialization/ClassMethods.html | 2 +- ActiveModel.html | 2 +- ActiveModel/SerializableResource.html | 2 +- ActiveModel/Serializer.html | 2 +- ActiveModel/Serializer/Adapter.html | 2 +- .../Serializer/Adapter/Attributes.html | 2 +- ActiveModel/Serializer/Adapter/Base.html | 2 +- ActiveModel/Serializer/Adapter/Json.html | 2 +- ActiveModel/Serializer/Adapter/JsonApi.html | 2 +- ActiveModel/Serializer/Adapter/Null.html | 2 +- ActiveModel/Serializer/ArraySerializer.html | 2 +- ActiveModel/Serializer/Association.html | 2 +- ActiveModel/Serializer/Associations.html | 2 +- .../Serializer/Associations/ClassMethods.html | 2 +- ActiveModel/Serializer/Attribute.html | 2 +- ActiveModel/Serializer/Attributes.html | 2 +- .../Serializer/Attributes/ClassMethods.html | 2 +- .../Serializer/BelongsToReflection.html | 2 +- ActiveModel/Serializer/Caching.html | 2 +- .../Serializer/Caching/ClassMethods.html | 2 +- .../Serializer/CollectionReflection.html | 2 +- .../Serializer/CollectionSerializer.html | 2 +- ActiveModel/Serializer/Configuration.html | 2 +- ActiveModel/Serializer/ErrorSerializer.html | 2 +- ActiveModel/Serializer/ErrorsSerializer.html | 2 +- ActiveModel/Serializer/Field.html | 2 +- ActiveModel/Serializer/Fieldset.html | 2 +- ActiveModel/Serializer/HasManyReflection.html | 2 +- ActiveModel/Serializer/HasOneReflection.html | 2 +- ActiveModel/Serializer/Links.html | 2 +- .../Serializer/Links/ClassMethods.html | 2 +- ActiveModel/Serializer/Lint.html | 2 +- ActiveModel/Serializer/Lint/Tests.html | 2 +- ActiveModel/Serializer/Meta.html | 2 +- ActiveModel/Serializer/Meta/ClassMethods.html | 2 +- ActiveModel/Serializer/Null.html | 2 +- ActiveModel/Serializer/Reflection.html | 2 +- .../Serializer/SingularReflection.html | 2 +- ActiveModel/Serializer/Type.html | 2 +- ActiveModel/Serializer/Type/ClassMethods.html | 2 +- ActiveModelSerializers.html | 2 +- ActiveModelSerializers/Adapter.html | 2 +- .../Adapter/Attributes.html | 2 +- ActiveModelSerializers/Adapter/Base.html | 2 +- ActiveModelSerializers/Adapter/Json.html | 2 +- ActiveModelSerializers/Adapter/JsonApi.html | 2 +- .../Adapter/JsonApi/Deserialization.html | 2 +- .../Adapter/JsonApi/Error.html | 2 +- .../Adapter/JsonApi/Jsonapi.html | 2 +- .../Adapter/JsonApi/Link.html | 2 +- .../Adapter/JsonApi/Meta.html | 2 +- .../Adapter/JsonApi/PaginationLinks.html | 2 +- .../Adapter/JsonApi/Relationship.html | 2 +- .../Adapter/JsonApi/ResourceIdentifier.html | 2 +- ActiveModelSerializers/Adapter/Null.html | 2 +- ActiveModelSerializers/Callbacks.html | 2 +- .../Callbacks/ClassMethods.html | 2 +- ActiveModelSerializers/Deprecate.html | 2 +- ActiveModelSerializers/Deserialization.html | 2 +- ActiveModelSerializers/JsonPointer.html | 2 +- ActiveModelSerializers/Jsonapi.html | 2 +- .../Jsonapi/ControllerSupport.html | 2 +- ActiveModelSerializers/KeyTransform.html | 2 +- ActiveModelSerializers/Logging.html | 2 +- .../Logging/ClassMethods.html | 2 +- .../Logging/LogSubscriber.html | 2 +- ActiveModelSerializers/Logging/Macros.html | 2 +- ActiveModelSerializers/Model.html | 2 +- ActiveModelSerializers/Railtie.html | 2 +- .../SerializableResource.html | 2 +- .../SerializationContext.html | 2 +- .../SerializationContext/UrlHelpers.html | 2 +- ActiveModelSerializers/Test.html | 2 +- ActiveModelSerializers/Test/Schema.html | 2 +- .../Test/Schema/AssertRequestSchema.html | 2 +- .../Test/Schema/AssertResponseSchema.html | 2 +- .../Test/Schema/AssertSchema.html | 2 +- ActiveModelSerializers/Test/Serializer.html | 2 +- .../Test/Serializer/AssertSerializer.html | 2 +- BulkCacheFetcher.html | 2 +- Grape.html | 2 +- Grape/ActiveModelSerializers.html | 2 +- Grape/Formatters.html | 2 +- Grape/Formatters/ActiveModelSerializers.html | 2 +- Grape/Helpers.html | 2 +- Grape/Helpers/ActiveModelSerializers.html | 2 +- Rails.html | 2 +- Rails/Generators.html | 2 +- Rails/Generators/ResourceGenerator.html | 2 +- Rails/Generators/SerializerGenerator.html | 2 +- _index.html | 68 +- file.0000-namespace.html | 214 +++ file.ARCHITECTURE.html | 265 +++ file.CHANGELOG.html | 1484 +++++++++++++++++ file.CONTRIBUTING.html | 207 +++ file.README.html | 2 +- file.STYLE.html | 186 +++ file.adapters.html | 346 ++++ file.add_pagination_links.html | 196 +++ file.add_root_key.html | 126 ++ file.caching.html | 135 ++ file.configuration_options.html | 191 +++ file.deserialization.html | 179 ++ file.ember-and-json-api.html | 189 +++ file.errors.html | 135 ++ file.getting_started.html | 208 +++ file.grape.html | 98 ++ file.instrumentation.html | 113 ++ file.key_transforms.html | 110 ++ file.logging.html | 88 + file.outside_controller_use.html | 133 ++ file.passing_arbitrary_options.html | 104 ++ file.rendering.html | 333 ++++ file.schema.html | 347 ++++ file.serialize_poro.html | 102 ++ file.serializers.html | 503 ++++++ file.template.html | 94 ++ file.test.html | 222 +++ file_list.html | 66 + index.html | 2 +- top-level-namespace.html | 2 +- 123 files changed, 6536 insertions(+), 96 deletions(-) create mode 100644 file.0000-namespace.html create mode 100644 file.ARCHITECTURE.html create mode 100644 file.CHANGELOG.html create mode 100644 file.CONTRIBUTING.html create mode 100644 file.STYLE.html create mode 100644 file.adapters.html create mode 100644 file.add_pagination_links.html create mode 100644 file.add_root_key.html create mode 100644 file.caching.html create mode 100644 file.configuration_options.html create mode 100644 file.deserialization.html create mode 100644 file.ember-and-json-api.html create mode 100644 file.errors.html create mode 100644 file.getting_started.html create mode 100644 file.grape.html create mode 100644 file.instrumentation.html create mode 100644 file.key_transforms.html create mode 100644 file.logging.html create mode 100644 file.outside_controller_use.html create mode 100644 file.passing_arbitrary_options.html create mode 100644 file.rendering.html create mode 100644 file.schema.html create mode 100644 file.serialize_poro.html create mode 100644 file.serializers.html create mode 100644 file.template.html create mode 100644 file.test.html diff --git a/ActionController.html b/ActionController.html index 96c14e0c..758d0e30 100644 --- a/ActionController.html +++ b/ActionController.html @@ -106,7 +106,7 @@ diff --git a/ActionController/Serialization.html b/ActionController/Serialization.html index 6e5cabeb..8bb1f450 100644 --- a/ActionController/Serialization.html +++ b/ActionController/Serialization.html @@ -339,7 +339,7 @@ diff --git a/ActionController/Serialization/ClassMethods.html b/ActionController/Serialization/ClassMethods.html index d84551e1..880b8625 100644 --- a/ActionController/Serialization/ClassMethods.html +++ b/ActionController/Serialization/ClassMethods.html @@ -165,7 +165,7 @@ diff --git a/ActiveModel.html b/ActiveModel.html index efcb32b6..114bbd59 100644 --- a/ActiveModel.html +++ b/ActiveModel.html @@ -120,7 +120,7 @@ subclassed to decorate a resource.

diff --git a/ActiveModel/SerializableResource.html b/ActiveModel/SerializableResource.html index 28e92406..0df0d07e 100644 --- a/ActiveModel/SerializableResource.html +++ b/ActiveModel/SerializableResource.html @@ -126,7 +126,7 @@ diff --git a/ActiveModel/Serializer.html b/ActiveModel/Serializer.html index 95a305a3..6dc52279 100644 --- a/ActiveModel/Serializer.html +++ b/ActiveModel/Serializer.html @@ -1755,7 +1755,7 @@ below is true:

diff --git a/ActiveModel/Serializer/Adapter.html b/ActiveModel/Serializer/Adapter.html index 89f54e71..67af0ede 100644 --- a/ActiveModel/Serializer/Adapter.html +++ b/ActiveModel/Serializer/Adapter.html @@ -147,7 +147,7 @@ diff --git a/ActiveModel/Serializer/Adapter/Attributes.html b/ActiveModel/Serializer/Adapter/Attributes.html index 74fb47b6..7f632679 100644 --- a/ActiveModel/Serializer/Adapter/Attributes.html +++ b/ActiveModel/Serializer/Adapter/Attributes.html @@ -239,7 +239,7 @@ diff --git a/ActiveModel/Serializer/Adapter/Base.html b/ActiveModel/Serializer/Adapter/Base.html index 7030934a..7c1e77c7 100644 --- a/ActiveModel/Serializer/Adapter/Base.html +++ b/ActiveModel/Serializer/Adapter/Base.html @@ -226,7 +226,7 @@ diff --git a/ActiveModel/Serializer/Adapter/Json.html b/ActiveModel/Serializer/Adapter/Json.html index 7990f272..5be507fb 100644 --- a/ActiveModel/Serializer/Adapter/Json.html +++ b/ActiveModel/Serializer/Adapter/Json.html @@ -239,7 +239,7 @@ diff --git a/ActiveModel/Serializer/Adapter/JsonApi.html b/ActiveModel/Serializer/Adapter/JsonApi.html index 33154215..128cd05a 100644 --- a/ActiveModel/Serializer/Adapter/JsonApi.html +++ b/ActiveModel/Serializer/Adapter/JsonApi.html @@ -240,7 +240,7 @@ diff --git a/ActiveModel/Serializer/Adapter/Null.html b/ActiveModel/Serializer/Adapter/Null.html index 6141378f..ab95b0e1 100644 --- a/ActiveModel/Serializer/Adapter/Null.html +++ b/ActiveModel/Serializer/Adapter/Null.html @@ -239,7 +239,7 @@ diff --git a/ActiveModel/Serializer/ArraySerializer.html b/ActiveModel/Serializer/ArraySerializer.html index 3707a4e2..158671dd 100644 --- a/ActiveModel/Serializer/ArraySerializer.html +++ b/ActiveModel/Serializer/ArraySerializer.html @@ -160,7 +160,7 @@ diff --git a/ActiveModel/Serializer/Association.html b/ActiveModel/Serializer/Association.html index 39e686ea..7e3d2ea6 100644 --- a/ActiveModel/Serializer/Association.html +++ b/ActiveModel/Serializer/Association.html @@ -583,7 +583,7 @@ diff --git a/ActiveModel/Serializer/Associations.html b/ActiveModel/Serializer/Associations.html index be1e6d36..4664ba66 100644 --- a/ActiveModel/Serializer/Associations.html +++ b/ActiveModel/Serializer/Associations.html @@ -263,7 +263,7 @@ not provided)

diff --git a/ActiveModel/Serializer/Associations/ClassMethods.html b/ActiveModel/Serializer/Associations/ClassMethods.html index d93864c8..34731549 100644 --- a/ActiveModel/Serializer/Associations/ClassMethods.html +++ b/ActiveModel/Serializer/Associations/ClassMethods.html @@ -488,7 +488,7 @@ diff --git a/ActiveModel/Serializer/Attribute.html b/ActiveModel/Serializer/Attribute.html index 229aa927..49d2a639 100644 --- a/ActiveModel/Serializer/Attribute.html +++ b/ActiveModel/Serializer/Attribute.html @@ -158,7 +158,7 @@ ActiveModel::Serializer class.

diff --git a/ActiveModel/Serializer/Attributes.html b/ActiveModel/Serializer/Attributes.html index 31802aca..480685da 100644 --- a/ActiveModel/Serializer/Attributes.html +++ b/ActiveModel/Serializer/Attributes.html @@ -115,7 +115,7 @@ diff --git a/ActiveModel/Serializer/Attributes/ClassMethods.html b/ActiveModel/Serializer/Attributes/ClassMethods.html index 9373871e..358c14a1 100644 --- a/ActiveModel/Serializer/Attributes/ClassMethods.html +++ b/ActiveModel/Serializer/Attributes/ClassMethods.html @@ -488,7 +488,7 @@ diff --git a/ActiveModel/Serializer/BelongsToReflection.html b/ActiveModel/Serializer/BelongsToReflection.html index 8cdb325d..7e01c375 100644 --- a/ActiveModel/Serializer/BelongsToReflection.html +++ b/ActiveModel/Serializer/BelongsToReflection.html @@ -167,7 +167,7 @@ diff --git a/ActiveModel/Serializer/Caching.html b/ActiveModel/Serializer/Caching.html index 5fc4a00b..c0994307 100644 --- a/ActiveModel/Serializer/Caching.html +++ b/ActiveModel/Serializer/Caching.html @@ -629,7 +629,7 @@ customize the cache key

diff --git a/ActiveModel/Serializer/Caching/ClassMethods.html b/ActiveModel/Serializer/Caching/ClassMethods.html index 1989722c..c752965d 100644 --- a/ActiveModel/Serializer/Caching/ClassMethods.html +++ b/ActiveModel/Serializer/Caching/ClassMethods.html @@ -1291,7 +1291,7 @@ called with a non-nil value. rubocop:disable Style/ClassVars

diff --git a/ActiveModel/Serializer/CollectionReflection.html b/ActiveModel/Serializer/CollectionReflection.html index dfef0203..f7a9e980 100644 --- a/ActiveModel/Serializer/CollectionReflection.html +++ b/ActiveModel/Serializer/CollectionReflection.html @@ -163,7 +163,7 @@ diff --git a/ActiveModel/Serializer/CollectionSerializer.html b/ActiveModel/Serializer/CollectionSerializer.html index e5f6925f..1add7d7f 100644 --- a/ActiveModel/Serializer/CollectionSerializer.html +++ b/ActiveModel/Serializer/CollectionSerializer.html @@ -703,7 +703,7 @@ the logic right here.

diff --git a/ActiveModel/Serializer/Configuration.html b/ActiveModel/Serializer/Configuration.html index 14eb0af8..e13b5b10 100644 --- a/ActiveModel/Serializer/Configuration.html +++ b/ActiveModel/Serializer/Configuration.html @@ -110,7 +110,7 @@ diff --git a/ActiveModel/Serializer/ErrorSerializer.html b/ActiveModel/Serializer/ErrorSerializer.html index c1bd0d4a..fc51de31 100644 --- a/ActiveModel/Serializer/ErrorSerializer.html +++ b/ActiveModel/Serializer/ErrorSerializer.html @@ -387,7 +387,7 @@ diff --git a/ActiveModel/Serializer/ErrorsSerializer.html b/ActiveModel/Serializer/ErrorsSerializer.html index d1a2bd22..48ccbb41 100644 --- a/ActiveModel/Serializer/ErrorsSerializer.html +++ b/ActiveModel/Serializer/ErrorsSerializer.html @@ -494,7 +494,7 @@ diff --git a/ActiveModel/Serializer/Field.html b/ActiveModel/Serializer/Field.html index 46419407..f51e89cc 100644 --- a/ActiveModel/Serializer/Field.html +++ b/ActiveModel/Serializer/Field.html @@ -405,7 +405,7 @@ block is evaluated in the context of the serializer.

diff --git a/ActiveModel/Serializer/Fieldset.html b/ActiveModel/Serializer/Fieldset.html index 2cf2f39a..6fd7e0c9 100644 --- a/ActiveModel/Serializer/Fieldset.html +++ b/ActiveModel/Serializer/Fieldset.html @@ -303,7 +303,7 @@ diff --git a/ActiveModel/Serializer/HasManyReflection.html b/ActiveModel/Serializer/HasManyReflection.html index 92ae4de0..0ff274c4 100644 --- a/ActiveModel/Serializer/HasManyReflection.html +++ b/ActiveModel/Serializer/HasManyReflection.html @@ -167,7 +167,7 @@ diff --git a/ActiveModel/Serializer/HasOneReflection.html b/ActiveModel/Serializer/HasOneReflection.html index 27192de8..0235f510 100644 --- a/ActiveModel/Serializer/HasOneReflection.html +++ b/ActiveModel/Serializer/HasOneReflection.html @@ -167,7 +167,7 @@ diff --git a/ActiveModel/Serializer/Links.html b/ActiveModel/Serializer/Links.html index c07ef456..0626af1b 100644 --- a/ActiveModel/Serializer/Links.html +++ b/ActiveModel/Serializer/Links.html @@ -115,7 +115,7 @@ diff --git a/ActiveModel/Serializer/Links/ClassMethods.html b/ActiveModel/Serializer/Links/ClassMethods.html index 2e71de78..3583ebd2 100644 --- a/ActiveModel/Serializer/Links/ClassMethods.html +++ b/ActiveModel/Serializer/Links/ClassMethods.html @@ -246,7 +246,7 @@ diff --git a/ActiveModel/Serializer/Lint.html b/ActiveModel/Serializer/Lint.html index 0ab3612e..bd913bcd 100644 --- a/ActiveModel/Serializer/Lint.html +++ b/ActiveModel/Serializer/Lint.html @@ -106,7 +106,7 @@ diff --git a/ActiveModel/Serializer/Lint/Tests.html b/ActiveModel/Serializer/Lint/Tests.html index ad441dea..3f8da6b2 100644 --- a/ActiveModel/Serializer/Lint/Tests.html +++ b/ActiveModel/Serializer/Lint/Tests.html @@ -901,7 +901,7 @@ required unless caching is enabled.

diff --git a/ActiveModel/Serializer/Meta.html b/ActiveModel/Serializer/Meta.html index 0988ff28..ec3d8493 100644 --- a/ActiveModel/Serializer/Meta.html +++ b/ActiveModel/Serializer/Meta.html @@ -115,7 +115,7 @@ diff --git a/ActiveModel/Serializer/Meta/ClassMethods.html b/ActiveModel/Serializer/Meta/ClassMethods.html index 8a477d25..8a9c0fd5 100644 --- a/ActiveModel/Serializer/Meta/ClassMethods.html +++ b/ActiveModel/Serializer/Meta/ClassMethods.html @@ -192,7 +192,7 @@ diff --git a/ActiveModel/Serializer/Null.html b/ActiveModel/Serializer/Null.html index 3e104bf6..28b93462 100644 --- a/ActiveModel/Serializer/Null.html +++ b/ActiveModel/Serializer/Null.html @@ -390,7 +390,7 @@ diff --git a/ActiveModel/Serializer/Reflection.html b/ActiveModel/Serializer/Reflection.html index 830204b8..f1bdde6e 100644 --- a/ActiveModel/Serializer/Reflection.html +++ b/ActiveModel/Serializer/Reflection.html @@ -729,7 +729,7 @@ association by its reflection.

diff --git a/ActiveModel/Serializer/SingularReflection.html b/ActiveModel/Serializer/SingularReflection.html index 6fdf2bca..d6c2ded1 100644 --- a/ActiveModel/Serializer/SingularReflection.html +++ b/ActiveModel/Serializer/SingularReflection.html @@ -163,7 +163,7 @@ diff --git a/ActiveModel/Serializer/Type.html b/ActiveModel/Serializer/Type.html index 80491ef0..1fa1f227 100644 --- a/ActiveModel/Serializer/Type.html +++ b/ActiveModel/Serializer/Type.html @@ -115,7 +115,7 @@ diff --git a/ActiveModel/Serializer/Type/ClassMethods.html b/ActiveModel/Serializer/Type/ClassMethods.html index 2afa4504..800cbad7 100644 --- a/ActiveModel/Serializer/Type/ClassMethods.html +++ b/ActiveModel/Serializer/Type/ClassMethods.html @@ -187,7 +187,7 @@ diff --git a/ActiveModelSerializers.html b/ActiveModelSerializers.html index 6c127f1f..d5ca8a1c 100644 --- a/ActiveModelSerializers.html +++ b/ActiveModelSerializers.html @@ -453,7 +453,7 @@ Style/AsciiComments TODO: implement!

diff --git a/ActiveModelSerializers/Adapter.html b/ActiveModelSerializers/Adapter.html index 2ade452b..a039583a 100644 --- a/ActiveModelSerializers/Adapter.html +++ b/ActiveModelSerializers/Adapter.html @@ -878,7 +878,7 @@ so that registering 'ActiveModelSerializers::Adapter::Json' and diff --git a/ActiveModelSerializers/Adapter/Attributes.html b/ActiveModelSerializers/Adapter/Attributes.html index 6a862b73..de610491 100644 --- a/ActiveModelSerializers/Adapter/Attributes.html +++ b/ActiveModelSerializers/Adapter/Attributes.html @@ -212,7 +212,7 @@ diff --git a/ActiveModelSerializers/Adapter/Base.html b/ActiveModelSerializers/Adapter/Base.html index 80ae1726..9066ab49 100644 --- a/ActiveModelSerializers/Adapter/Base.html +++ b/ActiveModelSerializers/Adapter/Base.html @@ -1073,7 +1073,7 @@ serialization_options(options).

diff --git a/ActiveModelSerializers/Adapter/Json.html b/ActiveModelSerializers/Adapter/Json.html index 369f71e0..74ee0270 100644 --- a/ActiveModelSerializers/Adapter/Json.html +++ b/ActiveModelSerializers/Adapter/Json.html @@ -320,7 +320,7 @@ diff --git a/ActiveModelSerializers/Adapter/JsonApi.html b/ActiveModelSerializers/Adapter/JsonApi.html index f7429b1a..48dadd2b 100644 --- a/ActiveModelSerializers/Adapter/JsonApi.html +++ b/ActiveModelSerializers/Adapter/JsonApi.html @@ -851,7 +851,7 @@ definition:

diff --git a/ActiveModelSerializers/Adapter/JsonApi/Deserialization.html b/ActiveModelSerializers/Adapter/JsonApi/Deserialization.html index 9014b8ec..595803a5 100644 --- a/ActiveModelSerializers/Adapter/JsonApi/Deserialization.html +++ b/ActiveModelSerializers/Adapter/JsonApi/Deserialization.html @@ -1050,7 +1050,7 @@ value.

diff --git a/ActiveModelSerializers/Adapter/JsonApi/Error.html b/ActiveModelSerializers/Adapter/JsonApi/Error.html index b4402d7a..31f852ed 100644 --- a/ActiveModelSerializers/Adapter/JsonApi/Error.html +++ b/ActiveModelSerializers/Adapter/JsonApi/Error.html @@ -462,7 +462,7 @@ parameter: A string indicating which query parameter caused the error diff --git a/ActiveModelSerializers/Adapter/JsonApi/Jsonapi.html b/ActiveModelSerializers/Adapter/JsonApi/Jsonapi.html index dd16336e..22b52fbc 100644 --- a/ActiveModelSerializers/Adapter/JsonApi/Jsonapi.html +++ b/ActiveModelSerializers/Adapter/JsonApi/Jsonapi.html @@ -356,7 +356,7 @@ meta diff --git a/ActiveModelSerializers/Adapter/JsonApi/Link.html b/ActiveModelSerializers/Adapter/JsonApi/Link.html index a0d25f60..f851728a 100644 --- a/ActiveModelSerializers/Adapter/JsonApi/Link.html +++ b/ActiveModelSerializers/Adapter/JsonApi/Link.html @@ -466,7 +466,7 @@ meta diff --git a/ActiveModelSerializers/Adapter/JsonApi/Meta.html b/ActiveModelSerializers/Adapter/JsonApi/Meta.html index d49f609c..092a5cae 100644 --- a/ActiveModelSerializers/Adapter/JsonApi/Meta.html +++ b/ActiveModelSerializers/Adapter/JsonApi/Meta.html @@ -292,7 +292,7 @@ diff --git a/ActiveModelSerializers/Adapter/JsonApi/PaginationLinks.html b/ActiveModelSerializers/Adapter/JsonApi/PaginationLinks.html index 3a8b8aa6..f150793f 100644 --- a/ActiveModelSerializers/Adapter/JsonApi/PaginationLinks.html +++ b/ActiveModelSerializers/Adapter/JsonApi/PaginationLinks.html @@ -431,7 +431,7 @@ diff --git a/ActiveModelSerializers/Adapter/JsonApi/Relationship.html b/ActiveModelSerializers/Adapter/JsonApi/Relationship.html index 787e68b0..581ae6a2 100644 --- a/ActiveModelSerializers/Adapter/JsonApi/Relationship.html +++ b/ActiveModelSerializers/Adapter/JsonApi/Relationship.html @@ -287,7 +287,7 @@ diff --git a/ActiveModelSerializers/Adapter/JsonApi/ResourceIdentifier.html b/ActiveModelSerializers/Adapter/JsonApi/ResourceIdentifier.html index 70fb1c02..5e62835b 100644 --- a/ActiveModelSerializers/Adapter/JsonApi/ResourceIdentifier.html +++ b/ActiveModelSerializers/Adapter/JsonApi/ResourceIdentifier.html @@ -255,7 +255,7 @@ diff --git a/ActiveModelSerializers/Adapter/Null.html b/ActiveModelSerializers/Adapter/Null.html index 22ae86c1..2046b295 100644 --- a/ActiveModelSerializers/Adapter/Null.html +++ b/ActiveModelSerializers/Adapter/Null.html @@ -208,7 +208,7 @@ diff --git a/ActiveModelSerializers/Callbacks.html b/ActiveModelSerializers/Callbacks.html index 4376c84e..06d18019 100644 --- a/ActiveModelSerializers/Callbacks.html +++ b/ActiveModelSerializers/Callbacks.html @@ -133,7 +133,7 @@ serialization and allow you to trigger logic. Available callbacks are:

diff --git a/ActiveModelSerializers/Callbacks/ClassMethods.html b/ActiveModelSerializers/Callbacks/ClassMethods.html index f161a548..d897b058 100644 --- a/ActiveModelSerializers/Callbacks/ClassMethods.html +++ b/ActiveModelSerializers/Callbacks/ClassMethods.html @@ -216,7 +216,7 @@ it is as_json, to_json, or serializable_hash

diff --git a/ActiveModelSerializers/Deprecate.html b/ActiveModelSerializers/Deprecate.html index 01693cb7..9b871d50 100644 --- a/ActiveModelSerializers/Deprecate.html +++ b/ActiveModelSerializers/Deprecate.html @@ -262,7 +262,7 @@ that it is planned to go away.

diff --git a/ActiveModelSerializers/Deserialization.html b/ActiveModelSerializers/Deserialization.html index b9b19df8..2cb10a2c 100644 --- a/ActiveModelSerializers/Deserialization.html +++ b/ActiveModelSerializers/Deserialization.html @@ -230,7 +230,7 @@ diff --git a/ActiveModelSerializers/JsonPointer.html b/ActiveModelSerializers/JsonPointer.html index f4c94edf..5f3a352b 100644 --- a/ActiveModelSerializers/JsonPointer.html +++ b/ActiveModelSerializers/JsonPointer.html @@ -180,7 +180,7 @@ diff --git a/ActiveModelSerializers/Jsonapi.html b/ActiveModelSerializers/Jsonapi.html index 3fd652a1..3127fec2 100644 --- a/ActiveModelSerializers/Jsonapi.html +++ b/ActiveModelSerializers/Jsonapi.html @@ -343,7 +343,7 @@ actionpack/lib/action_dispatch/http/parameters.rb

diff --git a/ActiveModelSerializers/Jsonapi/ControllerSupport.html b/ActiveModelSerializers/Jsonapi/ControllerSupport.html index 507f00d6..c62ab8f5 100644 --- a/ActiveModelSerializers/Jsonapi/ControllerSupport.html +++ b/ActiveModelSerializers/Jsonapi/ControllerSupport.html @@ -173,7 +173,7 @@ diff --git a/ActiveModelSerializers/KeyTransform.html b/ActiveModelSerializers/KeyTransform.html index 604cfe76..60488f44 100644 --- a/ActiveModelSerializers/KeyTransform.html +++ b/ActiveModelSerializers/KeyTransform.html @@ -524,7 +524,7 @@ deserialization in the JsonApi adapter.

diff --git a/ActiveModelSerializers/Logging.html b/ActiveModelSerializers/Logging.html index cc989344..a184026e 100644 --- a/ActiveModelSerializers/Logging.html +++ b/ActiveModelSerializers/Logging.html @@ -262,7 +262,7 @@ diff --git a/ActiveModelSerializers/Logging/ClassMethods.html b/ActiveModelSerializers/Logging/ClassMethods.html index d0bddbf9..c7c5b70d 100644 --- a/ActiveModelSerializers/Logging/ClassMethods.html +++ b/ActiveModelSerializers/Logging/ClassMethods.html @@ -177,7 +177,7 @@ diff --git a/ActiveModelSerializers/Logging/LogSubscriber.html b/ActiveModelSerializers/Logging/LogSubscriber.html index b1b6180c..734e8e4f 100644 --- a/ActiveModelSerializers/Logging/LogSubscriber.html +++ b/ActiveModelSerializers/Logging/LogSubscriber.html @@ -245,7 +245,7 @@ diff --git a/ActiveModelSerializers/Logging/Macros.html b/ActiveModelSerializers/Logging/Macros.html index 9f266791..a7f6b823 100644 --- a/ActiveModelSerializers/Logging/Macros.html +++ b/ActiveModelSerializers/Logging/Macros.html @@ -240,7 +240,7 @@ rendered. Adapted from:

diff --git a/ActiveModelSerializers/Model.html b/ActiveModelSerializers/Model.html index a4ebea0a..38a18827 100644 --- a/ActiveModelSerializers/Model.html +++ b/ActiveModelSerializers/Model.html @@ -752,7 +752,7 @@ ActiveModel::Errors :nocov:

diff --git a/ActiveModelSerializers/Railtie.html b/ActiveModelSerializers/Railtie.html index 94b26640..1845fd5a 100644 --- a/ActiveModelSerializers/Railtie.html +++ b/ActiveModelSerializers/Railtie.html @@ -114,7 +114,7 @@ diff --git a/ActiveModelSerializers/SerializableResource.html b/ActiveModelSerializers/SerializableResource.html index 146d491c..66fe0797 100644 --- a/ActiveModelSerializers/SerializableResource.html +++ b/ActiveModelSerializers/SerializableResource.html @@ -822,7 +822,7 @@ False when explicit adapter is falsy (nil or false)

diff --git a/ActiveModelSerializers/SerializationContext.html b/ActiveModelSerializers/SerializationContext.html index 3acd3f9b..4026bcbd 100644 --- a/ActiveModelSerializers/SerializationContext.html +++ b/ActiveModelSerializers/SerializationContext.html @@ -559,7 +559,7 @@ diff --git a/ActiveModelSerializers/SerializationContext/UrlHelpers.html b/ActiveModelSerializers/SerializationContext/UrlHelpers.html index 689423e2..4a093308 100644 --- a/ActiveModelSerializers/SerializationContext/UrlHelpers.html +++ b/ActiveModelSerializers/SerializationContext/UrlHelpers.html @@ -236,7 +236,7 @@ diff --git a/ActiveModelSerializers/Test.html b/ActiveModelSerializers/Test.html index 3e0f55bf..22f3d3fa 100644 --- a/ActiveModelSerializers/Test.html +++ b/ActiveModelSerializers/Test.html @@ -113,7 +113,7 @@ diff --git a/ActiveModelSerializers/Test/Schema.html b/ActiveModelSerializers/Test/Schema.html index 9e9657eb..f58361ff 100644 --- a/ActiveModelSerializers/Test/Schema.html +++ b/ActiveModelSerializers/Test/Schema.html @@ -463,7 +463,7 @@ diff --git a/ActiveModelSerializers/Test/Schema/AssertRequestSchema.html b/ActiveModelSerializers/Test/Schema/AssertRequestSchema.html index 0cde1e93..5bb88321 100644 --- a/ActiveModelSerializers/Test/Schema/AssertRequestSchema.html +++ b/ActiveModelSerializers/Test/Schema/AssertRequestSchema.html @@ -213,7 +213,7 @@ diff --git a/ActiveModelSerializers/Test/Schema/AssertResponseSchema.html b/ActiveModelSerializers/Test/Schema/AssertResponseSchema.html index d33a1f18..9a665155 100644 --- a/ActiveModelSerializers/Test/Schema/AssertResponseSchema.html +++ b/ActiveModelSerializers/Test/Schema/AssertResponseSchema.html @@ -213,7 +213,7 @@ diff --git a/ActiveModelSerializers/Test/Schema/AssertSchema.html b/ActiveModelSerializers/Test/Schema/AssertSchema.html index dfda7e98..8f183287 100644 --- a/ActiveModelSerializers/Test/Schema/AssertSchema.html +++ b/ActiveModelSerializers/Test/Schema/AssertSchema.html @@ -645,7 +645,7 @@ diff --git a/ActiveModelSerializers/Test/Serializer.html b/ActiveModelSerializers/Test/Serializer.html index 737fd98f..426e56a8 100644 --- a/ActiveModelSerializers/Test/Serializer.html +++ b/ActiveModelSerializers/Test/Serializer.html @@ -218,7 +218,7 @@ diff --git a/ActiveModelSerializers/Test/Serializer/AssertSerializer.html b/ActiveModelSerializers/Test/Serializer/AssertSerializer.html index 1e4f9c1f..bc886517 100644 --- a/ActiveModelSerializers/Test/Serializer/AssertSerializer.html +++ b/ActiveModelSerializers/Test/Serializer/AssertSerializer.html @@ -701,7 +701,7 @@ diff --git a/BulkCacheFetcher.html b/BulkCacheFetcher.html index b9642f9a..86717558 100644 --- a/BulkCacheFetcher.html +++ b/BulkCacheFetcher.html @@ -312,7 +312,7 @@ found objects, so you can use it for things like setting cache expiration.

diff --git a/Grape.html b/Grape.html index ca68ffa3..66276a49 100644 --- a/Grape.html +++ b/Grape.html @@ -124,7 +124,7 @@ render helper in Grape::Helpers::ActiveModelSerializers

diff --git a/Grape/ActiveModelSerializers.html b/Grape/ActiveModelSerializers.html index fc8aefb4..69facce5 100644 --- a/Grape/ActiveModelSerializers.html +++ b/Grape/ActiveModelSerializers.html @@ -101,7 +101,7 @@ diff --git a/Grape/Formatters.html b/Grape/Formatters.html index b09bd9d4..c758ab51 100644 --- a/Grape/Formatters.html +++ b/Grape/Formatters.html @@ -106,7 +106,7 @@ diff --git a/Grape/Formatters/ActiveModelSerializers.html b/Grape/Formatters/ActiveModelSerializers.html index e15df16c..240d115e 100644 --- a/Grape/Formatters/ActiveModelSerializers.html +++ b/Grape/Formatters/ActiveModelSerializers.html @@ -169,7 +169,7 @@ diff --git a/Grape/Helpers.html b/Grape/Helpers.html index 5d9003e6..4cbb3096 100644 --- a/Grape/Helpers.html +++ b/Grape/Helpers.html @@ -106,7 +106,7 @@ diff --git a/Grape/Helpers/ActiveModelSerializers.html b/Grape/Helpers/ActiveModelSerializers.html index 6b27eb2a..bd422446 100644 --- a/Grape/Helpers/ActiveModelSerializers.html +++ b/Grape/Helpers/ActiveModelSerializers.html @@ -186,7 +186,7 @@ posts.page, total_pages: posts.total_pages })

diff --git a/Rails.html b/Rails.html index 39d4464f..e9a2da6f 100644 --- a/Rails.html +++ b/Rails.html @@ -108,7 +108,7 @@ diff --git a/Rails/Generators.html b/Rails/Generators.html index 1995856d..f1ab10f2 100644 --- a/Rails/Generators.html +++ b/Rails/Generators.html @@ -108,7 +108,7 @@ diff --git a/Rails/Generators/ResourceGenerator.html b/Rails/Generators/ResourceGenerator.html index 613024d8..6d47321b 100644 --- a/Rails/Generators/ResourceGenerator.html +++ b/Rails/Generators/ResourceGenerator.html @@ -111,7 +111,7 @@ diff --git a/Rails/Generators/SerializerGenerator.html b/Rails/Generators/SerializerGenerator.html index acb7b058..336fa8ba 100644 --- a/Rails/Generators/SerializerGenerator.html +++ b/Rails/Generators/SerializerGenerator.html @@ -183,7 +183,7 @@ diff --git a/_index.html b/_index.html index 7fb8f3a6..c5a0228c 100644 --- a/_index.html +++ b/_index.html @@ -67,6 +67,72 @@
  • README
  • +
  • adapters
  • + + +
  • caching
  • + + +
  • configuration_options
  • + + +
  • deserialization
  • + + +
  • getting_started
  • + + +
  • instrumentation
  • + + +
  • key_transforms
  • + + +
  • logging
  • + + +
  • rendering
  • + + +
  • serializers
  • + + +
  • add_pagination_links
  • + + +
  • add_root_key
  • + + +
  • outside_controller_use
  • + + +
  • passing_arbitrary_options
  • + + +
  • serialize_poro
  • + + +
  • test
  • + + +
  • ember-and-json-api
  • + + +
  • grape
  • + + +
  • errors
  • + + +
  • schema
  • + + +
  • 0000-namespace
  • + + +
  • template
  • + +
    @@ -870,7 +936,7 @@ diff --git a/file.0000-namespace.html b/file.0000-namespace.html new file mode 100644 index 00000000..06aeeec6 --- /dev/null +++ b/file.0000-namespace.html @@ -0,0 +1,214 @@ + + + + + + File: 0000-namespace + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    + +

    Summary

    + +

    Provide a consistent API for the user of the AMS.

    + +

    Motivation

    + +

    The actual public API is defined under ActiveModelSerializers, +ActiveModel::Serializer and ActiveModel.

    + +

    At the ActiveModel::Serializer we have:

    +
    • +

      ActiveModel::Serializer.config

      +
    • +

      ActiveModel::Serializer

      +
    + +

    At the ActiveModelSerializers we have:

    +
    • +

      ActiveModelSerializers::Model

      +
    • +

      ActiveModelSerializers.logger

      +
    + +

    At ActiveModel we have:

    +
    • +

      ActiveModel::SerializableResource

      +
    + +

    The idea here is to provide a single namespace +ActiveModelSerializers to the user. Following the same idea we +have on other gems like Devise, +Refile +and Active +Job for example.

    + +

    This way we are clarifing the boundaries of ActiveModelSerializers +and Rails and make clear that the ActiveModel::Serializer +class is no longer the primary behavior of the ActiveModelSerializers.

    + +

    Detailed design

    + +

    New classes and modules organization

    + +

    Since this will be a big change we can do this on baby steps, read small +pull requests. A possible approach is:

    +
    • +

      All new code will be in lib/active_model_serializers/ using +the module namespace ActiveModelSerializers.

      +
    • +

      Move all content under ActiveModel::Serializer to be under +ActiveModelSerializers, the adapter is on this steps;

      +
    • +

      Move all content under ActiveModel to be under +ActiveModelSerializers, the SerializableResource +is on this step;

      +
    • +

      Change all public API that doesn't make sense, keeping in mind only to +keep this in the same namespace

      +
    • +

      Update the README;

      +
    • +

      Update the docs;

      +
    + +

    The following table represents the current and the desired classes and +modules at the first moment.

    + +

    | Current | Desired | Notes | +|——————————————————–|————————————————–|——————–| | +ActiveModelSerializers and +ActiveModel::Serializer | ActiveModelSerializers +| The main namespace | | ActiveModelSerializers.logger | +ActiveModelSerializers.logger || | +ActiveModelSerializers::Model | +ActiveModelSerializers::Model || | +ActiveModel::SerializableResource | +ActiveModelSerializers::SerializableResource || | +ActiveModel::Serializer | +ActiveModelSerializers::Serializer | The name can be discussed +in a future pull request. For example, we can rename this to +Resource following +this idea more info about naming in the next section| | +ActiveModel::Serializer.config | +ActiveModelSerializers.config ||

    + +

    Renaming of class and modules

    + +

    When moving some content to the new namespace we can find some names that +does not make much sense like +ActiveModel::Serializer::Adapter::JsonApi. Discussion of +renaming existing classes / modules and JsonApi objects will happen in +separate pull requests, and issues, and in the google doc docs.google.com/document/d/1rcrJr0sVcazY2Opd_6Kmv1iIwuHbI84s1P_NzFn-05c/edit?usp=sharing

    + +

    Some of names already have a definition.

    +
    • +

      Adapters get their own namespace under ActiveModelSerializers. E.g +ActiveModelSerializers::Adapter

      +
    • +

      Serializers get their own namespace under ActiveModelSerializers. E.g +ActiveModelSerializers::Serializer

      +
    + +

    Keeping compatibility

    + +

    All moved classes or modules be aliased to their old name and location with +deprecation warnings, such as was +done for CollectionSerializer.

    + +

    Drawbacks

    + +

    This will be a breaking change, so all users serializers will be broken +after a major bump. All pull requests will need to rebase since the +architeture will change a lot.

    + +

    Alternatives

    + +

    We can keep the way it is, and keep in mind to not add another namespace as +a public API.

    + +

    Unresolved questions

    + +

    What is the better class name to be used to the class that will be +inherited at the creation of a serializer. This can be discussed in other +RFC or directly via pull request.

    +
    + + + + + \ No newline at end of file diff --git a/file.ARCHITECTURE.html b/file.ARCHITECTURE.html new file mode 100644 index 00000000..98c77514 --- /dev/null +++ b/file.ARCHITECTURE.html @@ -0,0 +1,265 @@ + + + + + + File: ARCHITECTURE + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    This document focuses on architecture the 0.10.x version of +ActiveModelSerializers. If you are interested in the architecture of the +0.8 or 0.9 versions, please refer to the 0.8 +README or 0.9 +README.

    + +

    The original design is also available here.

    + +

    ARCHITECTURE

    + +

    An ActiveModel::Serializer wraps a serializable +resource and exposes an attributes method, among a few +others. It allows you to specify which attributes and associations should +be represented in the serializatation of the resource. It requires an +adapter to transform its attributes into a JSON document; it cannot be +serialized itself. It may be useful to think of it as a presenter.

    + +

    The ActiveModel::ArraySerializer represent a +collection of resources as serializers and, if there is no serializer, +primitives.

    + +

    The ActiveModel::Adapter describes the +structure of the JSON document generated from a serializer. For example, +the Attributes example represents each serializer as its +unmodified attributes. The JsonApi adapter represents the +serializer as a JSON API document.

    + +

    The +ActiveModelSerializers::SerializableResource +acts to coordinate the serializer(s) and adapter to an object that responds +to to_json, and as_json. It is used in the +controller to encapsulate the serialization resource when rendered. +However, it can also be used on its own to serialize a resource outside of +a controller, as well.

    + +

    Primitive handling

    + +

    Definitions: A primitive is usually a String or Array. There is no +serializer defined for them; they will be serialized when the resource is +converted to JSON (as_json or to_json). (The +below also applies for any object with no serializer.)

    + +

    ActiveModelSerializers doesn't handle primitives passed to render +json: at all.

    + +

    However, when a primitive value is an attribute or in a collection, it is +not modified.

    + +

    Internally, if no serializer can be found in the controller, the resource +is not decorated by ActiveModelSerializers.

    + +

    If the collection serializer (ArraySerializer) cannot identify a serializer +for a resource in its collection, it raises NoSerializerError +which is rescued in +ActiveModel::Serializer::Reflection#build_association which +sets the association value directly:

    + +
    reflection_options[:virtual_value] = association_value.try(:as_json) || association_value
    +
    + +

    (which is called by the adapter as +serializer.associations(*).)

    + +

    How options are parsed

    + +

    High-level overview:

    +
    • +

      For a collection

      +
    • +

      :serializer specifies the collection serializer and

      +
    • +

      :each_serializer specifies the serializer for each resource in +the collection.

      +
    • +

      For a single resource, the :serializer option is the resource +serializer.

      +
    • +

      Options are partitioned in serializer options and adapter options. Keys for +adapter options are specified by ADAPTER_OPTION_KEYS. +The remaining options are serializer options.

      +
    + +

    Details:

    +
    1. +

      ActionController::Serialization

      +
    2. +

      serializable_resource = +ActiveModelSerializers::SerializableResource.new(resource, options)

      +
      1. +

        options are partitioned into adapter_opts and +everything else (serializer_opts). The +adapter_opts keys are defined in +ActiveModelSerializers::SerializableResource::ADAPTER_OPTION_KEYS.

        +
      +
    3. +

      ActiveModelSerializers::SerializableResource

      +
    4. +

      if serializable_resource.serializer? (there is a serializer +for the resource, and an adapter is used.)

      +
      • +

        Where serializer? is use_adapter? && +!!(serializer)

        +
      • +

        Where use_adapter?: 'True when no explicit adapter given, +or explicit value is truthy (non-nil); False when explicit adapter is falsy +(nil or false)'

        +
      • +

        Where serializer:

        +
        1. +

          from explicit :serializer option, else

          +
        2. +

          implicitly from resource +ActiveModel::Serializer.serializer_for(resource)

          +
        +
      +
    5. +

      A side-effect of checking serializer is:

      +
      • +

        The :serializer option is removed from the serializer_opts +hash

        +
      • +

        If the :each_serializer option is present, it is removed from +the serializer_opts hash and set as the :serializer option

        +
      +
    6. +

      The serializer and adapter are created as

      +
      1. +

        serializer_instance = serializer.new(resource, +serializer_opts)

        +
      2. +

        adapter_instance = +ActiveModel::Serializer::Adapter.create(serializer_instance, +adapter_opts)

        +
      +
    7. +

      ActiveModel::Serializer::ArraySerializer#new

      +
    8. +

      If the serializer_instance was a ArraySerializer +and the :serializer serializer_opts is present, then that +serializer is passed into each resource.

      +
    9. +

      ActiveModel::Serializer#attributes is used by the adapter +to get the attributes for resource as defined by the serializer.

      +
    + +

    What does a 'serializable resource' look like?

    +
    • +

      An ActiveRecord::Base object.

      +
    • +

      Any Ruby object that passes the Lint +code.

      +
    + +

    ActiveModelSerializers provides a ActiveModelSerializers::Model, +which is a simple serializable PORO (Plain-Old Ruby Object).

    + +

    ActiveModelSerializers::Model may be used either as a template, or in +production code.

    + +
    class MyModel < ActiveModelSerializers::Model
    +  attr_accessor :id, :name, :level
    +end
    +
    + +

    The default serializer for MyModel would be +MyModelSerializer whether MyModel is an ActiveRecord::Base +object or not.

    + +

    Outside of the controller the rules are exactly the same +as for records. For example:

    + +
    render json: MyModel.new(level: 'awesome'), adapter: :json
    +
    + +

    would be serialized the same as

    + +
    ActiveModelSerializers::SerializableResource.new(MyModel.new(level: 'awesome'), adapter: :json).as_json
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.CHANGELOG.html b/file.CHANGELOG.html new file mode 100644 index 00000000..c7457a84 --- /dev/null +++ b/file.CHANGELOG.html @@ -0,0 +1,1484 @@ + + + + + + File: CHANGELOG + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    0.10.x

    + +

    master (unreleased)

    + +

    Breaking changes:

    + +

    Features: - #1668 +Exclude nil and empty links. (@sigmike) - #1426 +Add ActiveModelSerializers.config.default_includes (@empact)

    + +

    Fixes: - #1287 +Pass fields options from adapter to serializer. +(@vasilakisfil) - #1710 +Prevent association loading when include_data option is set +to false. (@groyoh) - #1747 +Improve jsonapi mime type registration for Rails 5 (@remear)

    + +

    Misc: - #1734 +Adds documentation for conditional attribute (@lambda2) - #1685 +Replace IncludeTree with IncludeDirective from +the jsonapi gem.

    + +

    v0.10.0 (2016-05-17)

    + +

    Breaking changes: - #1662 +Drop support for Rails 4.0 and Ruby 2.0.0. (@remear)

    + +

    Features: - #1677 +Add assert_schema, assert_request_schema, +assert_request_response_schema. (@bf4) - #1697 +Include actual exception message with custom exceptions; +Test::Schema exceptions are now +Minitest::Assertions. (@bf4) - #1699 +String/Lambda support for conditional attributes/associations (@mtsmfm) - +#1687 +Only calculate _cache_digest (in cache_key) when +skip_digest is false. (@bf4) - #1647 +Restrict usage of serializable_hash options to the +ActiveModel::Serialization and ActiveModel::Serializers::JSON interface. +(@bf4)

    + +

    Fixes: - #1700 +Support pagination link for Kaminari when no data is returned. (@iamnader) +- #1726 +Adds polymorphic option to association definition which includes +association type/nesting in serializer (@cgmckeever)

    + +

    Misc: - #1673 +Adds “How to” guide on using AMS with POROs (@DrSayre) - #1730 +Adds documentation for overriding default serializer based on conditions +(@groyoh/@cgmckeever)

    + +

    v0.10.0.rc5 (2016-04-04)

    + +

    Breaking changes:

    +
    • +

      #1645 +Changed :dashed key transform to :dash. (@remear)

      +
    • +

      #1574 +Default key case for the JsonApi adapter changed to dashed. (@remear)

      +
    + +

    Features: - #1645 +Transform keys referenced in values. (@remear) - #1650 +Fix serialization scope options scope, scope_name +take precedence over serialization_scope in the controller. +Fix tests that required tearing down dynamic methods. (@bf4) - #1644 +Include adapter name in cache key so that the same serializer can be +cached per adapter. (@bf4 via #1346 by @kevintyll) - #1642 +Prefer object.cache_key over the generated cache key. (@bf4 via #1346 by +@kevintyll) - #1637 +Make references to 'ActionController::Base.cache_store' explicit +in order to avoid issues when application controllers inherit from +'ActionController::API'. (@ncuesta) - #1633 +Yield 'serializer' to serializer association blocks. (@bf4) - #1616 +SerializableResource handles no serializer like controller. (@bf4) - #1618 +Get collection root key for empty collection from explicit serializer +option, when possible. (@bf4) - #1574 +Provide key translation. (@remear) - #1494 +Make serializers serializalbe (using the Attributes adapter by default). +(@bf4) - #1550 +Add Rails url_helpers to SerializationContext for use in +links. (@remear, @bf4) - #1004 +JSON API errors object implementation. - Only implements +detail and source as derived from +ActiveModel::Error - Provides checklist of remaining +questions and remaining parts of the spec. - #1515 +Adds support for symbols to the ActiveModel::Serializer.type +method. (@groyoh) - #1504 +Adds the changes missing from #1454 and add more tests for resource +identifier and relationship objects. Fix association block with link +returning data: nil.(@groyoh) - #1372 +Support cache_store.read_multi. (@LcpMarvel) - #1018 +Add more tests and docs for top-level links. (@leandrocp) - #1454 +Add support for relationship-level links and meta attributes. (@beauby) - +#1340 +Add support for resource-level meta. (@beauby)

    + +

    Fixes: - #1657 +Add missing missing require “active_support/json”. (@andreaseger) - #1661 +Fixes read_attribute_for_serialization not seeing methods +defined in serialization superclass (#1653, #1658, #1660), introduced in +#1650. (@bf4) - #1651 +Fix deserialization of nil relationships. (@NullVoxPopuli) - #1480 +Fix setting of cache_store from Rails configuration. (@bf4) Fix +unintentional mutating of value in memory cache store. (@groyoh) - #1622 +Fragment cache changed from per-record to per-serializer. Now, two +serializers that use the same model may be separately cached. (@lserman) - +#1478 +Cache store will now be correctly set when serializers are loaded +before Rails initializes. (@bf4) - #1570 +Fixed pagination issue with last page size. (@bmorrall) - #1516 +No longer return a nil href when only adding meta to a relationship link. +(@groyoh) - #1458 +Preserve the serializer type when fragment caching. (@bdmac) - #1477 +Fix fragment_cached? method to check if caching. (@bdmac) - +#1501 +Adds tests for SerializableResource::use_adapter?,doc typos (@domitian) - +#1488 +Require ActiveSupport's string inflections (@nate00)

    + +

    Misc: - #1608 +Move SerializableResource to ActiveModelSerializers (@groyoh) - #1602 +Add output examples to Adapters docs (@remear) - #1557 +Update docs regarding overriding the root key (@Jwan622) - #1471 +[Cleanup] Serializer caching is its own concern. (@bf4) - #1482 +Document JSON API implementation defs and progress in class. (@bf4) - #1551 +Added codebeat badge (@korzonek) - #1527 +Refactor fragment cache class. (@groyoh) - #1560 +Update rubocop and address its warnings. (@bf4 @groyoh) - #1545 +Document how to pass arbitrary options to the serializer +(@CodedBeardedSignedTaylor) - #1496 +Run all branches against JRuby on CI (@nadavshatz) - #1559 +Add a deprecation DSL. (@bf4 @groyoh) - #1543 +Add the changes missing from #1535. (@groyoh) - #1535 +Move the adapter and adapter folder to active_model_serializers folder and +changes the module namespace. (@domitian @bf4) - #1497 +Add JRuby-9000 to appveyor.yml(@corainchicago) - #1420 +Adds tests and documentation for polymorphism(@marcgarreau)

    + +

    v0.10.0.rc4 (2016-01-27)

    + +

    Breaking changes:

    +
    • +

      #1360 +#1369 +Drop support for Ruby 1.9.3 (@karaAJC, @maurogeorge)

      +
    • +

      #1131 +Remove Serializer#root_name (@beauby)

      +
    • +

      #1138 +Introduce Adapter::Base (@bf4)

      +
    • +

      Adapters now inherit Adapter::Base. 'Adapter' is now a module, no +longer a class.

      +
      • +

        using a class as a namespace that you also inherit from is complicated and +circular at times i.e. buggy (see github.com/rails-api/active_model_serializers/pull/1177)

        +
      • +

        The class methods on Adapter aren't necessarily related to the instance +methods, they're more Adapter functions.

        +
      • +

        named Base because it's a Rails-ism.

        +
      • +

        It helps to isolate and highlight what the Adapter interface actually is.

        +
      +
    • +

      #1418 +serialized collections now use the root option as is; now, only the root +derived from the serializer or object is always pluralized.

      +
    + +

    Features:

    +
    • +

      #1406 +Allow for custom dynamic values in JSON API links (@beauby)

      +
    • +

      #1270 +Adds assert_response_schema test helper (@maurogeorge)

      +
    • +

      #1099 +Adds assert_serializer test helper (@maurogeorge)

      +
    • +

      #1403 +Add support for if/unless on attributes/associations (@beauby)

      +
    • +

      #1248 +Experimental: Add support for JSON API deserialization (@beauby)

      +
    • +

      #1378 +Change association blocks to be evaluated in serializer scope, +rather than association scope. (@bf4)

      +
      • +

        Syntax changes from e.g. has_many :titles do customers.pluck(:title) +end (in #1356) to has_many :titles do +object.customers.pluck(:title) end

        +
      +
    • +

      #1356 +Add inline syntax for attributes and associations (@bf4 @beauby +@noahsilas)

      +
    • +

      Allows defining attributes so that they don't conflict with existing +methods. e.g. attribute :title do 'Mr. Topum Hat' +end

      +
    • +

      Allows defining associations so that they don't conflict with existing +methods. e.g. has_many :titles do customers.pluck(:title) +end

      +
      • +

        Allows dynamic associations, as compared to compare to using virtual_value. +e.g. has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]

        +
      +
    • +

      Removes dynamically defined methods on the serializer

      +
    • +

      #1336 +Added support for Grape >= 0.13, < 1.0 (@johnhamelink)

      +
    • +

      #1322 +Instrumenting rendering of resources (@bf4, @maurogeorge)

      +
    • +

      #1291 +Add logging (@maurogeorge)

      +
    • +

      #1272 +Add PORO serializable base class: ActiveModelSerializers::Model (@bf4)

      +
    • +

      #1255 +Make more class attributes inheritable (@bf4)

      +
    • +

      #1249 +Inheritance of serializer inheriting the cache configuration(@Rodrigora)

      +
    • +

      #1247 +Add support for toplevel JSON API links (@beauby)

      +
    • +

      #1246 +Add support for resource-level JSON API links (@beauby)

      +
    • +

      #1225 +Better serializer lookup, use nested serializer when it exists (@beauby)

      +
    • +

      #1213 +type directive for serializer to control type field with +json-api adapter (@youroff)

      +
    • +

      #1172 +Better serializer registration, get more than just the first module (@bf4)

      +
    • +

      #1158 +Add support for wildcards in include option (@beauby)

      +
    • +

      #1127 +Add support for nested associations for JSON and Attributes adapters via +the include option (@NullVoxPopuli, @beauby).

      +
    • +

      #1050 +Add support for toplevel jsonapi member (@beauby, @bf4)

      +
    • +

      #1251 +Rename ArraySerializer to CollectionSerializer for clarity, add +ActiveModelSerializers.config.collection_serializer (@bf4)

      +
    • +

      #1295 +Add config serializer_lookup_enabled that, when disabled, +requires serializers to explicitly specified. (@trek)

      +
    + +

    Fixes:

    +
    • +

      #1352 +Fix generators; Isolate Rails-specifc code in Railties (@dgynn, @bf4)

      +
    • +

      #1384[https://github.com/rails-api/active_model_serializers/pull/1384]Fix +database state leaking across tests (@bf4)

      +
    • +

      #1297 +Fix fields option to restrict relationships as well (@beauby)

      +
    • +

      #1239 +Fix duplicates in JSON API compound documents (@beauby)

      +
    • +

      #1214 +retrieve the key from the reflection options when building associations +(@NullVoxPopuli, @hut8)

      +
    • +

      #1358 +Handle serializer file paths with spaces (@rwstauner, @bf4)

      +
    • +

      #1195 +Fix id override (@beauby)

      +
    • +

      #1185 +Fix options passing in Json and Attributes adapters (@beauby)

      +
    + +

    Misc:

    +
    • +

      #1383 +Simplify reflections handling (@beauby)

      +
    • +

      #1370 +Simplify attributes handling via a mixin (@beauby)

      +
    • +

      #1301 +Mapping JSON API spec / schema to AMS (@bf4)

      +
    • +

      #1271 +Handle no serializer source file to digest (@bf4)

      +
    • +

      #1260 +Serialization and Cache Documentation (@bf4)

      +
    • +

      #1259 +Add more info to CONTRIBUTING (@bf4)

      +
    • +

      #1233 +Top-level meta and meta_key options no longer handled at serializer level +(@beauby)

      +
    • +

      #1232 +fields option no longer handled at serializer level (@beauby)

      +
    • +

      #1220 +Remove empty rubocop.rake (@maurogeorge)

      +
    • +

      #1178 +env CAPTURE_STDERR=false lets devs see hard failures (@bf4)

      +
    • +

      #1177 +Remove Adapter autoloads in favor of require (@bf4)

      +
    • +

      #1117 +FlattenJson adapter no longer inherits Json adapter, renamed to Attributes +(@bf4)

      +
    • +

      #1171 +add require statements to top of file (@shicholas)

      +
    • +

      #1167 +Delegate Serializer.attributes to Serializer.attribute (@bf4)

      +
    • +

      #1174 +Consistently refer to the 'JSON API' and the 'JsonApi' +adapter (@bf4)

      +
    • +

      #1173 +Comment private accessor warnings (@bf4)

      +
    • +

      #1166 +Prefer methods over instance variables (@bf4)

      +
    • +

      #1168 +Fix appveyor failure cache not being expired (@bf4)

      +
    • +

      #1161 +Remove duplicate test helper (@bf4)

      +
    • +

      #1360 +Update CI to test 2.2.2 -> 2.2.3 (@karaAJC)

      +
    • +

      #1371 +Refactor, update, create documentation (@bf4)

      +
    + +

    v0.10.0.rc3 (2015-09-16)

    +
    • +

      #1129 +Remove SerializableResource.serialize in favor of .new (@bf4)

      +
    • +

      #1155 +Outside controller use tutorial (@CodedBeardedSignedTaylor)

      +
    • +

      #1154 +Rubocop fixes for issues introduced by #1089 (@NullVoxPopuli)

      +
    • +

      #1089 +Add ActiveModelSerializers.logger with default null device (@bf4)

      +
    • +

      #1109 +Make better use of Minitest's lifecycle (@bf4)

      +
    • +

      #1144 +Fix Markdown to adapters documentation (@bacarini)

      +
    • +

      #1121 +Refactor add_links in JSONAPI adapter. (@beauby)

      +
    • +

      #1150 +Remove legacy method accidentally reintroduced in #1017 (@beauby)

      +
    • +

      #1149 +Update README with nested included association example. (@mattmueller)

      +
    • +

      #1110 +Add lint tests for AR models (@beauby)

      +
    • +

      #1131 +Extended format for JSONAPI include option (@beauby)

      +
    • +

      adds extended format for include option to JsonApi adapter

      +
    • +

      #1142 +Updating wording on cache expiry in README (@leighhalliday)

      +
    • +

      #1140 +Fix typo in fieldset exception (@lautis)

      +
    • +

      #1132 +Get rid of unnecessary instance variables, and implied dependencies. +(@beauby)

      +
    • +

      #1139 +Documentation for serializing resources without render (@PericlesTheo)

      +
    • +

      #1017 +Make Adapters registerable so they are not namespace-constrained (@bf4)

      +
    • +

      #1120 +Add windows platform to loading sqlite3 (@Eric-Guo)

      +
    • +

      #1123 +Remove url options (@bacarini)

      +
    • +

      #1093 +Factor with_adapter + force cache clear before each test. +(@beauby)

      +
    • +

      #1095 +Add documentation about configuration options. (@beauby)

      +
    • +

      #1069 +Add test coverage; account for no artifacts on CI (@bf4)

      +
    • +

      #1103 +Move id and json_api_type methods from +Serializer to JsonApi. (@beauby)

      +
    • +

      #1106 +Add Style enforcer (via Rubocop) (@bf4)

      +
    • +

      #1079 +Add ArraySerializer#object like Serializer (@bf4)

      +
    • +

      #1096 +Fix definition of serializer attributes with multiple calls to `attri… +(@beauby)

      +
    • +

      #1105 +Add ActiveRecord-backed fixtures. (@beauby)

      +
    • +

      #1108 +Better lint (@bf4)

      +
    • +

      #1102 +Remove remains of embed option. (@beauby)

      +
    • +

      #1090 +Clarify AMS dependencies (@bf4)

      +
    • +

      #1081 +Add configuration option to set resource type to singular/plural (@beauby)

      +
    • +

      #1067 +Fix warnings (@bf4)

      +
    • +

      #1066 +Adding appveyor to the project (@joaomdmoura, @Eric-Guo, @bf4)

      +
    • +

      #1071 +Make testing suite running and pass in Windows (@Eric-Guo, @bf4)

      +
    • +

      #1041 +Adding pagination links (@bacarini)

      +
    • +

      adds support for pagination links at top level of JsonApi +adapter

      +
    • +

      #1063 +Lead by example: lint PORO model (@bf4)

      +
    • +

      #1 +Test caller line parsing and digesting (@bf4)

      +
    • +

      #1048 +Let FlattenJson adapter decide it doesn't include meta (@bf4)

      +
    • +

      #1060 +Update fragment cache to support namespaced objects (@aaronlerch)

      +
    • +

      #1052 +Use underscored json_root when serializing a collection (@whatthewhat)

      +
    • +

      #1051 +Fix some invalid JSON in docs (@tjschuck)

      +
    • +

      #1049 +Fix incorrect s/options = {}/options ||= {} (@bf4)

      +
    • +

      #1037 +allow for type attribute (@lanej)

      +
    • +

      #1034 +allow id attribute to be overriden (@lanej)

      +
    • +

      #1035 +Fixed Comments highlight (@artLopez)

      +
    • +

      #1031 +Disallow to define multiple associations at once (@bolshakov)

      +
    • +

      #1032 +Wrap railtie requirement with rescue (@elliotlarson)

      +
    • +

      #1026 +Bump Version Number to 0.10.0.rc2 (@jfelchner)

      +
    • +

      #985 +Associations implementation refactoring (@bolshakov)

      +
    • +

      #954 +Encapsulate serialization in ActiveModel::SerializableResource (@bf4)

      +
    • +

      #972 +Capture app warnings on test run (@bf4)

      +
    • +

      #1019 +Improve README.md (@baojjeu)

      +
    • +

      #998 +Changing root to model class name (@joaomdmoura)

      +
    • +

      #1006 +Fix adapter inflection bug for api -> API (@bf4)

      +
    • +

      #1016 +require rails/railtie before subclassing Rails::Railtie (@bf4)

      +
    • +

      #1013 +Root option with empty array support (@vyrak, @mareczek)

      +
    • +

      #994 +Starting Docs structure (@joaomdmoura)

      +
    • +

      #1007 +Bug fix for ArraySerializer json_key (@jiajiawang)

      +
    • +

      #1003 +Fix transient test failures (@Rodrigora)

      +
    • +

      #996 +Add linter for serializable resource (@bf4)

      +
    • +

      #990 +Adding json-api meta test (@joaomdmoura)

      +
    • +

      #984 +Add option “key” to serializer associations (@Rodrigora)

      +
    • +

      #982 +Fix typo (@bf4)

      +
    • +

      #981 +Remove unused PORO#to_param (@bf4)

      +
    • +

      #978 +fix generators template bug (@regonn)

      +
    • +

      #975 +Fixes virtual value not being used (@GriffinHeart)

      +
    • +

      #970 +Fix transient tests failures (@Rodrigora)

      +
    • +

      #962 +Rendering objects that doesn't have serializers (@bf4, @joaomdmoura, +@JustinAiken)

      +
    • +

      #939 +Use a more precise generated cache key (@aaronlerch)

      +
    • +

      #971 +Restore has_one to generator (@bf4)

      +
    • +

      #965 +options fedault valueserializable_hash and as_json (@bf4)

      +
    • +

      #959 +TYPO on README.md (@kangkyu)

      +
    + +

    v0.10.0.rc2 (2015-06-16)

    +
    • +

      #958 +Splitting json adapter into two (@joaomdmoura)

      +
    • +

      adds FlattenJSON as default adapter

      +
    • +

      #953 +use model name to determine the type (@lsylvester)

      +
    • +

      uses model name to determine the type

      +
    • +

      #949 +Don't pass serializer option to associated serializers (@bf4, +@edwardloveall)

      +
    • +

      #902 +Added serializer file digest to the cache_key (@cristianbica)

      +
    • +

      #948 +AMS supports JSONAPI 1.0 instead of RC4 (@SeyZ)

      +
    • +

      #936 +Include meta when using json adapter with custom root (@chrisbranson)

      +
    • +

      #942 +Small code styling issue (@thiagofm)

      +
    • +

      #930 +Reverting PR #909 (@joaomdmoura)

      +
    • +

      #924 +Avoid unecessary calls to attribute methods when fragment caching +(@navinpeiris)

      +
    • +

      #925 +Updates JSON API Adapter to generate RC4 schema (@benedikt)

      +
    • +

      adds JSON API support 1.0

      +
    • +

      #918 +Adding rescue_with_handler to clear state (@ryansch)

      +
    • +

      #909 +Defining Json-API Adapter as Default (@joaomdmoura)

      +
    • +

      remove root key option and split JSON adapter

      +
    • +

      #914 +Prevent possible duplicated attributes in serializer (@groyoh)

      +
    • +

      #880 +Inabling subclasses serializers to inherit attributes (@groyoh)

      +
    • +

      #913 +Avoiding the serializer option when instantiating a new one for +ArraySerializer Fixed #911 (@groyoh)

      +
    • +

      #897 +Allow to define custom serializer for given class (@imanel)

      +
    • +

      #892 +Fixed a bug that appeared when json adapter serialize a nil association +(@groyoh)

      +
    • +

      #895 +Adding a test to cover 'meta' and 'meta_key' attr_readers +(@adomokos)

      +
    • +

      #894 +Fixing typos in README.md (@adomokos)

      +
    • +

      #888 +Changed duplicated test name in action controller test (@groyoh)

      +
    • +

      #890 +Remove unused method def_serializer (@JustinAiken)

      +
    • +

      #887 +Fixing tests on JRuby (@joaomdmoura)

      +
    • +

      #885 +Updates rails versions for test and dev (@tonyta)

      +
    + +

    v0.10.0.rc1 (2015-04-22)

    +
    • +

      #810 +Adding Fragment Cache to AMS (@joaomdmoura)

      +
    • +

      adds fragment cache support

      +
    • +

      #868 +Fixed a bug that appears when a nil association is included (@groyoh)

      +
    • +

      #861 +README: Add emphasis to single-word difference (@machty)

      +
    • +

      #858 +Included resource fixes (@mateomurphy)

      +
    • +

      #853 +RC3 Updates for JSON API (@mateomurphy)

      +
    • +

      #852 +Fix options merge order in each_association (@mateomurphy)

      +
    • +

      #850 +Use association value for determining serializer used (@mateomurphy)

      +
    • +

      #843 +Remove the mailing list from the README (@JoshSmith)

      +
    • +

      #842 +Add notes on how you can help to contributing documentation (@JoshSmith)

      +
    • +

      #833 +Cache serializers for class (@lsylvester)

      +
    • +

      #837 +Store options in array serializers (@kurko)

      +
    • +

      #836 +Makes passed in options accessible inside serializers (@kurko)

      +
    • +

      #773 +Make json api adapter 'include' option accept an array +(@sweatypitts)

      +
    • +

      #830 +Add contributing readme (@JoshSmith)

      +
    • +

      #811 +Reimplement serialization scope and scope_name (@mateomurphy)

      +
    • +

      #725 +Support has_one to be compatible with 0.8.x (@ggordon)

      +
    • +

      adds has_one attribute for backwards compatibility

      +
    • +

      #822 +Replace has_one with attribute in template (@bf4)

      +
    • +

      #821 +Fix explicit serializer for associations (@wjordan)

      +
    • +

      #798 +Fix lost test test_include_multiple_posts_and_linked +(@donbobka)

      +
    • +

      #807 +Add Overriding attribute methods section to README. (@alexstophel)

      +
    • +

      #693 +Cache Support at AMS 0.10.0 (@joaomdmoura)

      +
    • +

      adds cache support to attributes and associations.

      +
    • +

      #792 +Association overrides (@kurko)

      +
    • +

      adds method to override association

      +
    • +

      #794 +add to_param for correct URL generation (@carlesjove)

      +
    + +

    v0.10.0-pre

    + + +

    0.09.x

    + +

    v0.9.3 (2015/01/21 20:29 +00:00)

    + +

    Features: - #774 +Fix nested include attributes (@nhocki) - #771 +Make linked resource type names consistent with root names (@sweatypitts) - +#696 +Explicitly set serializer for associations (@ggordon) - #700 +sparse fieldsets (@arenoir) - #768 +Adds support for meta and meta_key attribute +(@kurko)

    + +

    v0.9.1 (2014/12/04 11:54 +00:00)

    +
    • +

      #707 +A Friendly Note on Which AMS Version to Use (@jherdman)

      +
    • +

      #730 +Fixes nested has_many links in JSONAPI (@kurko)

      +
    • +

      #718 +Allow overriding the adapter with render option (@ggordon)

      +
    • +

      #720 +Rename attribute with :key (0.8.x compatibility) (@ggordon)

      +
    • +

      #728 +Use type as key for linked resources (@kurko)

      +
    • +

      #729 +Use the new beta build env on Travis (@joshk)

      +
    • +

      #703 +Support serializer and each_serializer options in renderer (@ggordon, +@mieko)

      +
    • +

      #727 +Includes links inside of linked resources (@kurko)

      +
    • +

      #726 +Bugfix: include nested has_many associations (@kurko)

      +
    • +

      #722 +Fix infinite recursion (@ggordon)

      +
    • +

      #1 +Allow for the implicit use of ArraySerializer when :each_serializer is +specified (@mieko)

      +
    • +

      #692 +Include 'linked' member for json-api collections (@ggordon)

      +
    • +

      #714 +Define as_json instead of to_json (@guilleiguaran)

      +
    • +

      #710 +JSON-API: Don't include linked section if associations are empty +(@guilleiguaran)

      +
    • +

      #711 +Fixes rbx gems bundling on TravisCI (@kurko)

      +
    • +

      #709 +Add type key when association name is different than object type +(@guilleiguaran)

      +
    • +

      #708 +Handle correctly null associations (@guilleiguaran)

      +
    • +

      #691 +Fix embed option for associations (@jacob-s-son)

      +
    • +

      #689 +Fix support for custom root in JSON-API adapter (@guilleiguaran)

      +
    • +

      #685 +Serialize ids as strings in JSON-API adapter (@guilleiguaran)

      +
    • +

      #684 +Refactor adapters to implement support for array serialization +(@guilleiguaran)

      +
    • +

      #682 +Include root by default in JSON-API serializers (@guilleiguaran)

      +
    • +

      #625 +Add DSL for urls (@JordanFaust)

      +
    • +

      #677 +Add support for embed: :ids option for in associations (@guilleiguaran)

      +
    • +

      #681 +Check superclasses for Serializers (@quainjn)

      +
    • +

      #680 +Add support for root keys (@NullVoxPopuli)

      +
    • +

      #675 +Support Rails 4.2.0 (@tricknotes)

      +
    • +

      #667 +Require only activemodel instead of full rails (@guilleiguaran)

      +
    • +

      #653 +Add “_test” suffix to JsonApi::HasManyTest filename. (@alexgenco)

      +
    • +

      #631 +Update build badge URL (@craiglittle)

      +
    + +

    0.9.0.alpha1 - January 7, 2014

    + +

    0.9.0.pre

    +
    • +

      The following methods were removed

      +
    • +

      Model#active_model_serializer

      +
    • +

      Serializer#include!

      +
    • +

      Serializer#include?

      +
    • +

      Serializer#attr_disabled=

      +
    • +

      Serializer#cache

      +
    • +

      Serializer#perform_caching

      +
    • +

      Serializer#schema (needs more discussion)

      +
    • +

      Serializer#attribute

      +
    • +

      Serializer#include_#name? (filter method added)

      +
    • +

      Serializer#attributes (took a hash)

      +
    • +

      The following things were added

      +
    • +

      Serializer#filter method

      +
    • +

      CONFIG object

      +
    • +

      Remove support for ruby 1.8 versions.

      +
    • +

      Require rails >= 3.2.

      +
    • +

      Serializers for associations are being looked up in a parent +serializer's namespace first. Same with controllers' namespaces.

      +
    • +

      Added a "prefix" option in case you want to use a different version of +serializer.

      +
    • +

      Serializers default namespace can be set in +default_serializer_options and inherited by associations.

      +
    • +

      Beginning +of rewrite: c65d387705ec534db171712671ba7fcda4f49f68

      +
    + +

    0.08.x

    + +

    v0.8.3 (2014/12/10 14:45 +00:00)

    +
    • +

      #753 +Test against Ruby 2.2 on Travis CI (@tricknotes)

      +
    • +

      #745 +Missing a word (@jockee)

      +
    + +

    v0.8.2 (2014/09/01 21:00 +00:00)

    +
    • +

      #612 +Feature/adapter (@bolshakov)

      +
    • +

      adds adapters pattern

      +
    • +

      #615 +Rails does not support const_defined? in development mode (@tpitale)

      +
    • +

      #613 +README: typo fix on attributes (@spk)

      +
    • +

      #614 +Fix rails 4.0.x build. (@arthurnn)

      +
    • +

      #610 +ArraySerializer (@bolshakov)

      +
    • +

      #607 +ruby syntax highlights (@zigomir)

      +
    • +

      #602 +Add DSL for associations (@JordanFaust)

      +
    + +

    0.8.1 (May 6, 2013)

    +
    • +

      Fix bug whereby a serializer using 'options' would blow up.

      +
    + +

    0.8.0 (May 5, 2013)

    +
    • +

      Attributes can now have optional types.

      +
    • +

      A new DefaultSerializer ensures that POROs behave the same way as +ActiveModels.

      +
    • +

      If you wish to override ActiveRecord::Base#to_Json, you can now require +'active_record/serializer_override'. We don't recommend you do +this, but many users do, so we've left it optional.

      +
    • +

      Fixed a bug where ActionController wouldn't always have MimeResponds.

      +
    • +

      An optinal caching feature allows you to cache JSON & hashes that AMS +uses. Adding 'cached true' to your Serializers will turn on this +cache.

      +
    • +

      URL helpers used inside of Engines now work properly.

      +
    • +

      Serializers now can filter attributes with only and +except:

      +
    + +

    UserSerializer.new(user, only: [:first_name, :last_name]) +UserSerializer.new(user, except: :first_name)

    +
    • +

      Basic Mongoid support. We now include our mixins in the right place.

      +
    • +

      On Ruby 1.8, we now generate an id method that properly +serializes id columns. See issue #127 for more.

      +
    • +

      Add an alias for scope method to be the name of the context. +By default this is current_user. The name is automatically +set when using serialization_scope in the controller.

      +
    • +

      Pass through serialization options (such as :include) when a +model has no serializer defined.

      +
    + +

    0.7.0 (March 6, 2013)

    +
    • +

      embed_key option to allow embedding by attributes other than +IDs

      +
    • +

      Fix rendering nil with custom serializer

      +
    • +

      Fix global self.root = false

      +
    • +

      Add support for specifying the serializer for an association as a String

      +
    • +

      Able to specify keys on the attributes method

      +
    • +

      Serializer Reloading via ActiveSupport::DescendantsTracker

      +
    • +

      Reduce double map to once; Fixes datamapper eager loading.

      +
    + +

    0.6.0 (October 22, 2012)

    +
    • +

      Serialize sets properly

      +
    • +

      Add root option to ArraySerializer

      +
    • +

      Support polymorphic associations

      +
    • +

      Support :each_serializer in ArraySerializer

      +
    • +

      Add scope method to easily access the scope in the serializer

      +
    • +

      Fix regression with Rails 3.2.6; add Rails 4 support

      +
    • +

      Allow serialization_scope to be disabled with serialization_scope nil

      +
    • +

      Array serializer should support pure ruby objects besides serializers

      +
    + +

    0.05.x

    + +

    0.5.2 (June 5, 2012)

    + +

    0.5.1 (May 23, 2012)

    + +

    0.5.0 (May 16, 2012)

    +
    • +

      First tagged version

      +
    • +

      Changes generators to always generate an ApplicationSerializer

      +
    + +

    0.1.0 (December 21, 2011)

    + +

    First Commit as Rails Serializers 0.0.1

    + +

    (December 1, 2011).

    + +

    Prehistory

    + +
    + + + + + \ No newline at end of file diff --git a/file.CONTRIBUTING.html b/file.CONTRIBUTING.html new file mode 100644 index 00000000..74b8e4be --- /dev/null +++ b/file.CONTRIBUTING.html @@ -0,0 +1,207 @@ + + + + + + File: CONTRIBUTING + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Have an issue?

    + +

    Before opening an issue, try the following:

    + +
    Consult the documentation
    + +

    See if your issue can be resolved by information in the documentation.

    + + +
    Check for an existing issue
    + +

    Take a look at the issues to see if a similar one has already been created. +If one exists, please add any additional information that might expedite +resolution.

    + +

    Open an issue

    + +

    If the documentation wasn't able to help resolve the issue and no issue +already exists, please open a new issue with the following in mind:

    +
    • +

      Please make sure only to include one issue per report. If you encounter +multiple, unrelated issues, please report them as such.

      +
    • +

      Be detailed. Provide backtraces and example code when possible. Provide +information about your environment. e.g., Ruby version, rails version, etc.

      +
    • +

      Own your issue. Actively participate in the discussion and help drive the +issue to closure.

      +
    • +

      If you resolve your own issue, please share the details on the issue and +close it out. Others might have the same issue and sharing solutions is +helpful.

      +
    + +

    Contributing

    + +

    Contributing can be done in many ways and is not exclusive to code. If you +have thoughts on a particular issue or feature, we encourage you to open +new issues for discussion or add your comments to existing ones.

    + +

    Pull requests

    + +

    We also gladly welcome pull requests. When preparing to work on pull +request, please adhere to these standards:

    +
    • +

      Base work on the master branch unless fixing an issue with 0.9-stable +or 0.8-stable

      +
    • +

      Squash your commits and regularly rebase off master.

      +
    • +

      Provide a description of the changes contained in the pull request.

      +
    • +

      Note any specific areas that should be reviewed.

      +
    • +

      Include tests.

      +
    • +

      The test suite must pass on supported Ruby +versions

      +
    • +

      Include updates to the documentation +where applicable.

      +
    • +

      Update the CHANGELOG +to the appropriate sections with a brief description of the changes.

      +
    • +

      Do not change the VERSION file.

      +
    + +

    Running tests

    + +

    Run all tests

    + +

    $ rake test

    + +

    Run a single test suite

    + +

    $ rake test TEST=path/to/test.rb

    + +

    Run a single test

    + +

    $ rake test TEST=path/to/test.rb +TESTOPTS="--name=test_something"

    + +

    Run tests against different Rails versions by setting the RAILS_VERSION +variable and bundling gems. (save this script somewhere executable and run +from top of AMS repository)

    + +
    #!/usr/bin/env bash
    +
    +rcommand='puts YAML.load_file("./.travis.yml")["env"]["matrix"].join(" ").gsub("RAILS_VERSION=", "")'
    +versions=$(ruby -ryaml -e "$rcommand")
    +
    +for version in ${versions[@]}; do
    +  export RAILS_VERSION="$version"
    +  rm -f Gemfile.lock
    +  bundle check || bundle --local || bundle
    +  bundle exec rake test
    +  if [ "$?" -eq 0 ]; then
    +    # green in ANSI
    +    echo -e "\033[32m **** Tests passed against Rails ${RAILS_VERSION} **** \033[0m"
    +  else
    +    # red in ANSI
    +    echo -e "\033[31m **** Tests failed against Rails ${RAILS_VERSION} **** \033[0m"
    +    read -p '[Enter] any key to continue, [q] to quit...' prompt
    +    if [ "$prompt" = 'q' ]; then
    +      unset RAILS_VERSION
    +      exit 1
    +    fi
    +fi
    +  unset RAILS_VERSION
    +done
    +
    + + + + + \ No newline at end of file diff --git a/file.README.html b/file.README.html index 0c888667..dbfa707b 100644 --- a/file.README.html +++ b/file.README.html @@ -253,7 +253,7 @@ information.

    diff --git a/file.STYLE.html b/file.STYLE.html new file mode 100644 index 00000000..816a5ebc --- /dev/null +++ b/file.STYLE.html @@ -0,0 +1,186 @@ + + + + + + File: STYLE + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    STYLE

    + +

    Code and comments

    +
    • +

      We are actively working to identify tasks under the label Good +for New Contributors.

      +
    • +

      Changelog +Missing is an easy way to help out.

      +
    • +

      Fix +a bug.

      +
    • +

      Ready for PR - A well defined bug, needs someone to PR a fix.

      +
    • +

      Bug - Anything that is broken.

      +
    • +

      Regression - A bug that did not exist in previous versions and isn't a +new feature (applied in tandem with Bug).

      +
    • +

      Performance - A performance related issue. We could track this as a bug, +but usually these would have slightly lower priority than standard bugs.

      +
    • +

      Develop +new features.

      +
    • +

      Improve +code quality.

      +
    • +

      Improve +amount of code exercised by tests.

      +
    • +

      Fix +RuboCop (Style) TODOS.

      +
    • +

      Delete and offsense, run rake rubocop (or possibly rake +rubocop:auto_correct), and submit a PR.

      +
    • +

      We are also encouraging comments to substantial changes (larger than +bugfixes and simple features) under an "RFC" (Request for Comments) +process before we start active development. Look for the RFC +label.

      +
    + +

    Pull requests

    +
    • +

      If the tests pass and the pull request looks good, a maintainer will merge +it.

      +
    • +

      If the pull request needs to be changed,

      +
    • +

      you can change it by updating the branch you generated the pull request +from

      +
      • +

        either by adding more commits, or

        +
      • +

        by force pushing to it

        +
      +
    • +

      A maintainer can make any changes themselves and manually merge the code +in.

      +
    + +

    Commit messages

    + + +

    About Pull Requests (PR's)

    + + +

    Issue Labeling

    + +

    ActiveModelSerializers uses a subset of StandardIssueLabels +for Github Issues. You can see our +labels here.

    +
    + + + + + \ No newline at end of file diff --git a/file.adapters.html b/file.adapters.html new file mode 100644 index 00000000..3b05eab8 --- /dev/null +++ b/file.adapters.html @@ -0,0 +1,346 @@ + + + + + + File: adapters + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Adapters

    + +

    ActiveModelSerializers offers the ability to configure which adapter to use +both globally and/or when serializing (usually when rendering).

    + +

    The global adapter configuration is set on ActiveModelSerializers.config. It +should be set only once, preferably at initialization.

    + +

    For example:

    + +
    ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
    +
    + +

    or

    + +
    ActiveModelSerializers.config.adapter = :json_api
    +
    + +

    or

    + +
    ActiveModelSerializers.config.adapter = :json
    +
    + +

    The local adapter option is in the format adapter: adapter, +where adapter is any of the same values as set globally.

    + +

    The configured adapter can be set as a symbol, class, or class name, as +described in Advanced +adapter configuration.

    + +

    The Attributes adapter does not include a root key. It is just +the serialized attributes.

    + +

    Use either the JSON or JSON API adapters if you +want the response document to have a root key.

    + +

    Built in Adapters

    + +

    Attributes - Default

    + +

    It's the default adapter, it generates a json response without a root +key. Doesn't follow any specific convention.

    + +
    Example output
    + +
    {
    +  "title": "Title 1",
    +  "body": "Body 1",
    +  "publish_at": "2020-03-16T03:55:25.291Z",
    +  "author": {
    +    "first_name": "Bob",
    +    "last_name": "Jones"
    +  },
    +  "comments": [
    +    {
    +      "body": "cool"
    +    },
    +    {
    +      "body": "awesome"
    +    }
    +  ]
    +}
    +
    + +

    JSON

    + +

    The json response is always rendered with a root key.

    + +

    The root key can be overridden by: * passing the root option +in the render call. See details in the Rendering Guides. * setting +the type of the serializer. See details in the Serializers Guide.

    + +

    Doesn't follow any specific convention.

    + +
    Example output
    + +
    {
    +  "post": {
    +    "title": "Title 1",
    +    "body": "Body 1",
    +    "publish_at": "2020-03-16T03:55:25.291Z",
    +    "author": {
    +      "first_name": "Bob",
    +      "last_name": "Jones"
    +    },
    +    "comments": [{
    +      "body": "cool"
    +    }, {
    +      "body": "awesome"
    +    }]
    +  }
    +}
    +
    + +

    JSON API

    + +

    This adapter follows version 1.0 of the format specified in jsonapi.org/format.

    + +
    Example output
    + +
    {
    +  "data": {
    +    "id": "1337",
    +    "type": "posts",
    +    "attributes": {
    +      "title": "Title 1",
    +      "body": "Body 1",
    +      "publish-at": "2020-03-16T03:55:25.291Z"
    +    },
    +    "relationships": {
    +      "author": {
    +        "data": {
    +          "id": "1",
    +          "type": "authors"
    +        }
    +      },
    +      "comments": {
    +        "data": [{
    +          "id": "7",
    +          "type": "comments"
    +        }, {
    +          "id": "12",
    +          "type": "comments"
    +        }]
    +      }
    +    },
    +    "links": {
    +      "post-authors": "https://example.com/post_authors"
    +    },
    +    "meta": {
    +      "rating": 5,
    +      "favorite-count": 10
    +    }
    +  }
    +}
    +
    + +

    Included

    + +

    It will include the associated resources in the +"included" member when the resource names are +included in the include option. Including nested associated +resources is also supported.

    + +
    render json: @posts, include: ['author', 'comments', 'comments.author']
    +  # or
    +  render json: @posts, include: 'author,comments,comments.author'
    +
    + +

    In addition, two types of wildcards may be used:

    +
    • +

      * includes one level of associations.

      +
    • +

      ** includes all recursively.

      +
    + +

    These can be combined with other paths.

    + +
    render json: @posts, include: '**' # or '*' for a single layer
    +
    + +

    The format of the include option can be either:

    +
    • +

      a String composed of a comma-separated list of relationship paths.

      +
    • +

      an Array of Symbols and Hashes.

      +
    • +

      a mix of both.

      +
    + +

    The following would render posts and include:

    +
    • +

      the author

      +
    • +

      the author's comments, and

      +
    • +

      every resource referenced by the author's comments (recursively).

      +
    + +

    It could be combined, like above, with other paths in any combination +desired.

    + +
    render json: @posts, include: 'author.comments.**'
    +
    + +
    Security Considerations
    + +

    Since the included options may come from the query params (i.e. +user-controller):

    + +
    render json: @posts, include: params[:include]
    +
    + +

    The user could pass in include=**.

    + +

    We recommend filtering any user-supplied includes appropriately.

    + +

    Advanced adapter configuration

    + +

    Registering an adapter

    + +

    The default adapter can be configured, as above, to use any class given to +it.

    + +

    An adapter may also be specified, e.g. when rendering, as a class or as a +symbol. If a symbol, then the adapter must be, e.g. +:great_example, +ActiveModelSerializers::Adapter::GreatExample, or registered.

    + +

    There are two ways to register an adapter:

    + +

    1) The simplest, is to subclass +ActiveModelSerializers::Adapter::Base, e.g. the below will +register the Example::UsefulAdapter as +"example/useful_adapter".

    + +
    module Example
    +  class UsefulAdapter < ActiveModelSerializers::Adapter::Base
    +  end
    +end
    +
    + +

    You'll notice that the name it registers is the underscored namespace +and class.

    + +

    Under the covers, when the +ActiveModelSerializers::Adapter::Base is subclassed, it +registers the subclass as +register("example/useful_adapter", +Example::UsefulAdapter)

    + +

    2) Any class can be registered as an adapter by calling +register directly on the +ActiveModelSerializers::Adapter class. e.g., the below +registers MyAdapter as :special_adapter.

    + +
    class MyAdapter; end
    +ActiveModelSerializers::Adapter.register(:special_adapter, MyAdapter)
    +
    + +

    Looking up an adapter

    + +

    | Method | Return value | | :———— |:—————| | +ActiveModelSerializers::Adapter.adapter_map | A Hash of all +known adapters { adapter_name => adapter_class } | | +ActiveModelSerializers::Adapter.adapters | A (sorted) Array of +all known adapter_names | | +ActiveModelSerializers::Adapter.lookup(name_or_klass) | The +adapter_class, else raises an +ActiveModelSerializers::Adapter::UnknownAdapter error | | +ActiveModelSerializers::Adapter.adapter_class(adapter) | +Delegates to ActiveModelSerializers::Adapter.lookup(adapter) | +| ActiveModelSerializers::Adapter.configured_adapter | A +convenience method for +ActiveModelSerializers::Adapter.lookup(config.adapter) |

    + +

    The registered adapter name is always a String, but may be looked up as a +Symbol or String. Helpfully, the Symbol or String is underscored, so that +get(:my_adapter) and get("MyAdapter") +may both be used.

    + +

    For more information, see the +Adapter class on GitHub

    +
    + + + + + \ No newline at end of file diff --git a/file.add_pagination_links.html b/file.add_pagination_links.html new file mode 100644 index 00000000..80ba79d0 --- /dev/null +++ b/file.add_pagination_links.html @@ -0,0 +1,196 @@ + + + + + + File: add_pagination_links + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    How to add pagination links

    + +

    JSON API adapter

    + +

    Pagination links will be included in your response automatically as long as +the resource is paginated and if you are using the JsonApi +adapter.

    + +

    If you want pagination links in your response, use Kaminari or WillPaginate.

    + +

    Although the others adapters does not have this feature, it is possible to +implement pagination links to JSON adapter. For more +information about it, please see in our docs

    + +
    Kaminari examples
    + +
    #array
    +@posts = Kaminari.paginate_array([1, 2, 3]).page(3).per(1)
    +render json: @posts
    +
    +#active_record
    +@posts = Post.page(3).per(1)
    +render json: @posts
    +
    + +
    WillPaginate examples
    + +
    #array
    +@posts = [1,2,3].paginate(page: 3, per_page: 1)
    +render json: @posts
    +
    +#active_record
    +@posts = Post.page(3).per_page(1)
    +render json: @posts
    +
    + +
    ActiveModelSerializers.config.adapter = :json_api
    +
    + +

    ex: json { "data": [ { "type": +"articles", "id": "3", +"attributes": { "title": "JSON API paints +my bikeshed!", "body": "The shortest article. +Ever.", "created": +"2015-05-22T14:56:29.000Z", "updated": +"2015-05-22T14:56:28.000Z" } } ], +"links": { "self": +"http://example.com/articles?page[number]=3&page[size]=1", +"first": +"http://example.com/articles?page[number]=1&page[size]=1", +"prev": +"http://example.com/articles?page[number]=2&page[size]=1", +"next": +"http://example.com/articles?page[number]=4&page[size]=1", +"last": +"http://example.com/articles?page[number]=13&page[size]=1" } } +

    + +

    ActiveModelSerializers pagination relies on a paginated collection with the +methods current_page, total_pages, and +size, such as are supported by both Kaminari or WillPaginate.

    + +

    JSON adapter

    + +

    If you are using JSON adapter, pagination links will not be +included automatically, but it is possible to do so using meta +key.

    + +

    Add this method to your base API controller.

    + +
    def pagination_dict(object)
    +  {
    +    current_page: object.current_page,
    +    next_page: object.next_page,
    +    prev_page: object.prev_page,
    +    total_pages: object.total_pages,
    +    total_count: object.total_count
    +  }
    +end
    +
    + +

    Then, use it on your render method.

    + +
    render json: posts, meta: pagination_dict(posts)
    +
    + +

    ex. json { "posts": [ { "id": 2, +"title": "JSON API paints my bikeshed!", +"body": "The shortest article. Ever." } ], +"meta": { "current_page": 3, +"next_page": 4, "prev_page": 2, +"total_pages": 10, "total_count": 10 } }

    + +

    You can also achieve the same result if you have a helper method that adds +the pagination info in the meta tag. For instance, in your action specify a +custom serializer.

    + +
    render json: @posts, each_serializer: PostPreviewSerializer, meta: meta_attributes(@post)
    +
    + +
    #expects pagination!
    +def meta_attributes(resource, extra_meta = {})
    +  {
    +    current_page: resource.current_page,
    +    next_page: resource.next_page,
    +    prev_page: resource.prev_page,
    +    total_pages: resource.total_pages,
    +    total_count: resource.total_count
    +  }.merge(extra_meta)
    +end
    +
    + +

    Attributes adapter

    + +

    This adapter does not allow us to use meta key, due to that it +is not possible to add pagination links.

    +
    + + + + + \ No newline at end of file diff --git a/file.add_root_key.html b/file.add_root_key.html new file mode 100644 index 00000000..a6cdee4b --- /dev/null +++ b/file.add_root_key.html @@ -0,0 +1,126 @@ + + + + + + File: add_root_key + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    How to add root key

    + +

    Add the root key to your API is quite simple with ActiveModelSerializers. +The Adapter is what determines the format of your JSON +response. The default adapter is the Attributes which +doesn't have the root key, so your response is something similar to:

    + +
    {
    +  "id": 1,
    +  "title": "Awesome Post Tile",
    +  "content": "Post content"
    +}
    +
    + +

    In order to add the root key you need to use the JSON Adapter, +you can change this in an initializer:

    + +
    ActiveModelSerializers.config.adapter = :json
    +
    + +

    You can also specify a class as adapter, as long as it complies with the +ActiveModelSerializers adapters interface. It will add the root key to all +your serialized endpoints.

    + +

    ex:

    + +
    {
    +  "post": {
    +    "id": 1,
    +    "title": "Awesome Post Tile",
    +    "content": "Post content"
    +  }
    +}
    +
    + +

    or if it returns a collection:

    + +
    {
    +  "posts": [
    +    {
    +      "id": 1,
    +      "title": "Awesome Post Tile",
    +      "content": "Post content"
    +    },
    +    {
    +      "id": 2,
    +      "title": "Another Post Tile",
    +      "content": "Another post content"
    +    }
    +  ]
    +}
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.caching.html b/file.caching.html new file mode 100644 index 00000000..4ae7d5fb --- /dev/null +++ b/file.caching.html @@ -0,0 +1,135 @@ + + + + + + File: caching + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Caching

    + +

    To cache a serializer, call cache and pass its options. The +options are the same options of ActiveSupport::Cache::Store, +plus a key option that will be the prefix of the object cache +on a pattern +"#{key}/#{object.id}-#{object.updated_at}".

    + +

    The cache support is optimized to use the cached object in multiple +request. An object cached on a show request will be reused at +the index. If there is a relationship with another cached +serializer it will also be created and reused automatically.

    + +

    [NOTE] Every object is individually cached.

    + +

    [NOTE] The cache is automatically expired after an object is +updated, but it's not deleted.

    + +
    cache(options = nil) # options:
    +
    + +

    expires_in, compress, force, race_condition_ttl

    + +

    Take the example bellow:

    + +
    class PostSerializer < ActiveModel::Serializer
    +  cache key: 'post', expires_in: 3.hours
    +  attributes :title, :body
    +
    +  has_many :comments
    +end
    +
    + +

    On this example every Post object will be cached with the key +"post/#{post.id}-#{post.updated_at}". You can use +this key to expire it as you want, but in this case it will be +automatically expired after 3 hours.

    + +

    Fragment Caching

    + +

    If there is some API endpoint that shouldn't be fully cached, you can +still optimise it, using Fragment Cache on the attributes and relationships +that you want to cache.

    + +

    You can define the attribute by using only or +except option on cache method.

    + +

    [NOTE] Cache serializers will be used at their +relationships

    + +

    Example:

    + +
    class PostSerializer < ActiveModel::Serializer
    +  cache key: 'post', expires_in: 3.hours, only: [:title]
    +  attributes :title, :body
    +
    +  has_many :comments
    +end
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.configuration_options.html b/file.configuration_options.html new file mode 100644 index 00000000..a4183f98 --- /dev/null +++ b/file.configuration_options.html @@ -0,0 +1,191 @@ + + + + + + File: configuration_options + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Configuration Options

    + +

    The following configuration options can be set on +ActiveModelSerializers.config, preferably inside an +initializer.

    + +

    General

    + +
    adapter
    + +

    The adapter to use.

    + +

    Possible values:

    +
    • +

      :attributes (default)

      +
    • +

      :json

      +
    • +

      :json_api

      +
    + +
    serializer_lookup_enabled
    + +

    Enable automatic serializer lookup.

    + +

    Possible values:

    +
    • +

      true (default)

      +
    • +

      false

      +
    + +

    When false, serializers must be explicitly specified.

    + +
    key_transform
    + +

    The key transform to use.

    + +

    | Option | Result | |—-|—-| | :camel | ExampleKey | | +:camel_lower | exampleKey | | :dash | example-key +| | :unaltered | the original, unaltered key | | +:underscore | example_key | | nil | use the +adapter default |

    + +

    Each adapter has a default key transform configured:

    + +

    | Adapter | Default Key Transform | |—-|—-| | Json | +:unaltered | | JsonApi | :dash |

    + +

    config.key_transform is a global override of the adapter +default. Adapters still prefer the render option +:key_transform over this setting.

    + +

    NOTE: Key transforms can be expensive operations. If key transforms are +unnecessary for the application, setting config.key_transform +to :unaltered will provide a performance boost.

    + +
    default_includes
    + +

    What relationships to serialize by default. Default: +'*', which includes one level of related objects. See +includes for more info.

    + +

    JSON API

    + +
    jsonapi_resource_type
    + +

    Sets whether the type +of the resource should be singularized or +pluralized when it is not explicitly +specified by the serializer

    + +

    Possible values:

    +
    • +

      :singular

      +
    • +

      :plural (default)

      +
    + +
    jsonapi_include_toplevel_object
    + +

    Include a top +level jsonapi member in the response document.

    + +

    Possible values:

    +
    • +

      true

      +
    • +

      false (default)

      +
    + +
    jsonapi_version
    + +

    The latest version of the spec to which the API conforms.

    + +

    Default: '1.0'.

    + +

    Used when jsonapi_include_toplevel_object is +true

    + +
    jsonapi_toplevel_meta
    + +

    Optional top-level metadata. Not included if empty.

    + +

    Default: {}.

    + +

    Used when jsonapi_include_toplevel_object is +true

    + +

    Hooks

    + +

    To run a hook when ActiveModelSerializers is loaded, use +ActiveSupport.on_load(:action_controller) do end

    +
    + + + + + \ No newline at end of file diff --git a/file.deserialization.html b/file.deserialization.html new file mode 100644 index 00000000..f9c42af7 --- /dev/null +++ b/file.deserialization.html @@ -0,0 +1,179 @@ + + + + + + File: deserialization + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Deserialization

    + +

    This is currently an experimental feature. The interface may +change.

    + +

    JSON API

    + +

    The ActiveModelSerializers::Deserialization defines two +methods (namely jsonapi_parse and +jsonapi_parse!), which take a Hash or an instance +of ActionController::Parameters representing a JSON API +payload, and return a hash that can directly be used to create/update +models. The bang version throws an InvalidDocument exception +when parsing fails, whereas the “safe” version simply returns an empty +hash.

    +
    • +

      Parameters

      +
    • +

      document: Hash or ActionController::Parameters +instance

      +
    • +

      options:

      +
      • +

        only: Array of whitelisted fields

        +
      • +

        except: Array of blacklisted fields

        +
      • +

        keys: Hash of fields the name of which needs to be modified +(e.g. { :author => :user, :date => :created_at })

        +
      +
    + +

    Examples:

    + +
    class PostsController < ActionController::Base
    +  def create
    +    Post.create(create_params)
    +  end
    +
    +  def create_params
    +    ActiveModelSerializers::Deserialization.jsonapi_parse(params, only: [:title, :content, :author])
    +  end
    +end
    +
    + +

    Given a JSON API document,

    + +
    document = {
    +  'data' => {
    +    'id' => 1,
    +    'type' => 'post',
    +    'attributes' => {
    +      'title' => 'Title 1',
    +      'date' => '2015-12-20'
    +    },
    +    'relationships' => {
    +      'author' => {
    +        'data' => {
    +          'type' => 'user',
    +          'id' => '2'
    +        }
    +      },
    +      'second_author' => {
    +        'data' => nil
    +      },
    +      'comments' => {
    +        'data' => [{
    +          'type' => 'comment',
    +          'id' => '3'
    +        },{
    +          'type' => 'comment',
    +          'id' => '4'
    +        }]
    +      }
    +    }
    +  }
    +}
    +
    + +

    The entire document can be parsed without specifying any options: +ruby ActiveModelSerializers::Deserialization.jsonapi_parse(document) +#=> # { # title: 'Title 1', # date: '2015-12-20', # +author_id: 2, # second_author_id: nil # comment_ids: [3, 4] # }

    + +

    and fields, relationships, and polymorphic relationships can be specified +via the options:

    + +
    ActiveModelSerializers::Deserialization
    +  .jsonapi_parse(document, only: [:title, :date, :author],
    +                           keys: { date: :published_at },
    +                           polymorphic: [:author])
    +#=>
    +# {
    +#   title: 'Title 1',
    +#   published_at: '2015-12-20',
    +#   author_id: '2',
    +#   author_type: 'user'
    +# }
    +
    + +

    Attributes/Json

    + +

    There is currently no deserialization for those adapters.

    +
    + + + + + \ No newline at end of file diff --git a/file.ember-and-json-api.html b/file.ember-and-json-api.html new file mode 100644 index 00000000..6957217a --- /dev/null +++ b/file.ember-and-json-api.html @@ -0,0 +1,189 @@ + + + + + + File: ember-and-json-api + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Integrating with Ember and JSON API

    + + +

    Preparation

    + +

    Note: This guide assumes that ember-cli is used for your ember +app.

    + +

    The JSON API specification calls for hyphens for multi-word separators. +ActiveModelSerializers uses underscores. To solve this, in Ember, both the +adapter and the serializer will need some modifications:

    + +

    Server-Side Changes

    + +

    there are multiple mimetypes for json that should all be parsed similarly, +so in config/initializers/mime_types.rb: “`ruby api_mime_types += %W( application/vnd.api+json text/x-json application/json )

    + +

    Mime::Type.unregister :json Mime::Type.register 'application/json', +:json, api_mime_types “`

    + +

    Adapter Changes

    + +
    // app/adapters/application.js
    +import DS from 'ember-data';
    +import ENV from "../config/environment";
    +
    +export default  DS.JSONAPIAdapter.extend({
    +  namespace: 'api',
    +  // if your rails app is on a different port from your ember app
    +  // this can be helpful for development.
    +  // in production, the host for both rails and ember should be the same.
    +  host: ENV.host,
    +
    +  // allows the multiword paths in urls to be underscored
    +  pathForType: function(type) {
    +    let underscored = Ember.String.underscore(type);
    +    return Ember.String.pluralize(underscored);
    +  },
    +
    +  // allows queries to be sent along with a findRecord
    +  // hopefully Ember / EmberData will soon have this built in
    +  // ember-data issue tracked here:
    +  // https://github.com/emberjs/data/issues/3596
    +  urlForFindRecord(id, modelName, snapshot) {
    +    let url = this._super(...arguments);
    +    let query = Ember.get(snapshot, 'adapterOptions.query');
    +    if(query) {
    +      url += '?' + Ember.$.param(query);
    +    }
    +    return url;
    +  }
    +});
    + +

    Serializer Changes

    + +
    // app/serializers/application.js
    +import Ember from 'ember';
    +import DS from 'ember-data';
    +var underscore = Ember.String.underscore;
    +
    +export default DS.JSONAPISerializer.extend({
    +  keyForAttribute: function(attr) {
    +    return underscore(attr);
    +  },
    +
    +  keyForRelationship: function(rawKey) {
    +    return underscore(rawKey);
    +  }
    +});
    + +

    Including Nested Resources

    + +

    Previously, store.find and store.findRecord did +not allow specification of any query params. The ActiveModelSerializers +default for the include parameter is to be nil +meaning that if any associations are defined in your serializer, only the +id and type will be in the +relationships structure of the JSON API response. For more on +include usage, see: The JSON API include examples

    + +

    With the above modifications, you can execute code as below in order to +include nested resources while doing a find query.

    + +
    store.findRecord('post', postId, { adapterOptions: { query: { include: 'comments' } } });
    +
    + +

    will generate the path +/posts/{postId}?include='comments'

    + +

    So then in your controller, you'll want to be sure to have something +like: ruby render json: @post, include: params[:include]

    + +

    If you want to use include on a collection, you'd write +something like this:

    + +
    store.query('post', { include: 'comments' });
    +
    + +

    which will generate the path /posts?include='comments'

    +
    + + + + + \ No newline at end of file diff --git a/file.errors.html b/file.errors.html new file mode 100644 index 00000000..e693a994 --- /dev/null +++ b/file.errors.html @@ -0,0 +1,135 @@ + + + + + + File: errors + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    JSON API Errors

    + +

    Rendering error documents requires specifying the error serializer(s):

    +
    • +

      Serializer:

      +
    • +

      For a single resource: serializer: +ActiveModel::Serializer::ErrorSerializer.

      +
    • +

      For a collection: serializer: +ActiveModel::Serializer::ErrorsSerializer, each_serializer: +ActiveModel::Serializer::ErrorSerializer.

      +
    + +

    The resource MUST have a non-empty associated +#errors object. The errors object must have a +#messages method that returns a hash of error name to array of +descriptions.

    + +

    Use in controllers

    + +
    resource = Profile.new(name: 'Name 1',
    +                       description: 'Description 1',
    +                       comments: 'Comments 1')
    +resource.errors.add(:name, 'cannot be nil')
    +resource.errors.add(:name, 'must be longer')
    +resource.errors.add(:id, 'must be a uuid')
    +
    +render json: resource, status: 422, adapter: :json_api, serializer: ActiveModel::Serializer::ErrorSerializer
    +# #=>
    +#  { :errors =>
    +#    [
    +#      { :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
    +#      { :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
    +#      { :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
    +#    ]
    +#  }.to_json
    +
    + +

    Direct error document generation

    + +
    options = nil
    +resource = ModelWithErrors.new
    +resource.errors.add(:name, 'must be awesome')
    +
    +serializable_resource = ActiveModelSerializers::SerializableResource.new(
    +  resource, {
    +    serializer: ActiveModel::Serializer::ErrorSerializer,
    +    adapter: :json_api
    +  })
    +serializable_resource.as_json(options)
    +# #=>
    +# {
    +#   :errors =>
    +#     [
    +#       { :source => { :pointer => '/data/attributes/name' }, :detail => 'must be awesome' }
    +#     ]
    +# }
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.getting_started.html b/file.getting_started.html new file mode 100644 index 00000000..73334d18 --- /dev/null +++ b/file.getting_started.html @@ -0,0 +1,208 @@ + + + + + + File: getting_started + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Getting Started

    + +

    Creating a Serializer

    + +

    The easiest way to create a new serializer is to generate a new resource, +which will generate a serializer at the same time:

    + +
    $ rails g resource post title:string body:string
    + +

    This will generate a serializer in +app/serializers/post_serializer.rb for your new model. You can +also generate a serializer for an existing model with the serializer +generator:

    + +
    $ rails g serializer post
    + +

    The generated serializer will contain basic attributes and +has_many/has_one/belongs_to +declarations, based on the model. For example:

    + +
    class PostSerializer < ActiveModel::Serializer
    +  attributes :title, :body
    +
    +  has_many :comments
    +  has_one :author
    +end
    +
    + +

    and

    + +
    class CommentSerializer < ActiveModel::Serializer
    +  attributes :name, :body
    +
    +  belongs_to :post_id
    +end
    +
    + +

    The attribute names are a whitelist of attributes to be +serialized.

    + +

    The has_many, has_one, and +belongs_to declarations describe relationships between +resources. By default, when you serialize a Post, you will get +its Comments as well.

    + +

    For more information, see Serializers.

    + +

    Namespaced Models

    + +

    When serializing a model inside a namespace, such as +Api::V1::Post, ActiveModelSerializers will expect the +corresponding serializer to be inside the same namespace (namely +Api::V1::PostSerializer).

    + +

    Model Associations and Nested Serializers

    + +

    When declaring a serializer for a model with associations, such as: +ruby class PostSerializer < ActiveModel::Serializer has_many +:comments end ActiveModelSerializers will look for +PostSerializer::CommentSerializer in priority, and fall back +to ::CommentSerializer in case the former does not exist. This +allows for more control over the way a model gets serialized as an +association of an other model.

    + +

    For example, in the following situation:

    + +
    class CommentSerializer < ActiveModel::Serializer
    +  attributes :body, :date, :nb_likes
    +end
    +
    +class PostSerializer < ActiveModel::Serializer
    +  has_many :comments
    +  class CommentSerializer < ActiveModel::Serializer
    +    attributes :body_short
    +  end
    +end
    +
    + +

    ActiveModelSerializers will use +PostSerializer::CommentSerializer (thus including only the +:body_short attribute) when serializing a Comment +as part of a Post, but use ::CommentSerializer +when serializing a Comment directly (thus including +:body, :date, :nb_likes).

    + +

    Extending a Base ApplicationSerializer

    + +

    By default, new serializers descend from +ActiveModel::Serializer. However, if you wish to share +behavior across your serializers, you can create an +ApplicationSerializer at +app/serializers/application_serializer.rb:

    + +
    class ApplicationSerializer < ActiveModel::Serializer
    +end
    +
    + +

    Then any newly-generated serializers will automatically descend from +ApplicationSerializer.

    + +
    $ rails g serializer post
    + +

    Now generates:

    + +
    class PostSerializer < ApplicationSerializer
    +  attributes :id
    +end
    +````
    +
    +## Rails Integration
    +
    +ActiveModelSerializers will automatically integrate with your Rails app,
    +so you won't need to update your controller.
    +This is a example of how the controller will look:
    +
    + +

    ruby class PostsController < ApplicationController

    + +

    def show @post = Post.find(params) render json: @post +end

    + +

    end “`

    + +

    If you wish to use Rails url helpers for link generation, e.g., +link(:resources) { resources_url }, ensure your application +sets Rails.application.routes.default_url_options.

    + +
    Rails.application.routes.default_url_options = {
    +    host: 'example.com'
    +}
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.grape.html b/file.grape.html new file mode 100644 index 00000000..08dbe034 --- /dev/null +++ b/file.grape.html @@ -0,0 +1,98 @@ + + + + + + File: grape + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Integration with Grape

    + +

    Grape is an opinionated +micro-framework for creating REST-like APIs in ruby.

    + +

    ActiveModelSerializers currently supports Grape >= 0.13, < 1.0

    + +

    To add Grape support, +enable the formatter and helper functions by including +Grape::ActiveModelSerializers in your base endpoint. For +example:

    + +
    module Example
    +  class Dummy < Grape::API
    +    require 'grape/active_model_serializers'
    +    include Grape::ActiveModelSerializers
    +    mount Example::V1::Base
    +  end
    +end
    +
    + +

    Aside from this, configuration of +ActiveModelSerializers is exactly the same.

    +
    + + + + + \ No newline at end of file diff --git a/file.instrumentation.html b/file.instrumentation.html new file mode 100644 index 00000000..e37a9be7 --- /dev/null +++ b/file.instrumentation.html @@ -0,0 +1,113 @@ + + + + + + File: instrumentation + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Instrumentation

    + +

    ActiveModelSerializers uses the ActiveSupport::Notification +API, which allows for subscribing to events, such as for logging.

    + +

    Events

    + +

    Name:

    + +

    render.active_model_serializers

    + +

    Payload (example):

    + +
    {
    +  serializer: PostSerializer,
    +  adapter: ActiveModelSerializers::Adapter::Attributes
    +}
    +
    + +

    Subscribing:

    + +
    ActiveSupport::Notifications.subscribe 'render.active_model_serializers' do |name, started, finished, unique_id, data|
    +  # whatever
    +end
    +ActiveSupport::Notifications.subscribe 'render.active_model_serializers' do |*args|
    +  event = ActiveSupport::Notifications::Event.new(*args)
    +  # event.payload
    +  # whatever
    +end
    +
    + +

    LogSubscriber

    + +

    ActiveModelSerializers includes an +ActiveModelSerializers::LogSubscriber that attaches to +render.active_model_serializers.

    +
    + + + + + \ No newline at end of file diff --git a/file.key_transforms.html b/file.key_transforms.html new file mode 100644 index 00000000..b8eefacb --- /dev/null +++ b/file.key_transforms.html @@ -0,0 +1,110 @@ + + + + + + File: key_transforms + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Key Transforms

    + +

    Key Transforms modify the casing of keys and keys referenced in values in +serialized responses.

    + +

    Provided key transforms:

    + +

    | Option | Result | |—-|—-| | :camel | ExampleKey | | +:camel_lower | exampleKey | | :dash | example-key +| | :unaltered | the original, unaltered key | | +:underscore | example_key | | nil | use the +adapter default |

    + +

    Key translation precedence is as follows:

    + +
    Adapter option
    + +

    key_transform is provided as an option via render.

    + +
    json: posts, each_serializer: PostSerializer, key_transform: :camel_lower
    + +
    Configuration option
    + +

    key_transform is set in +ActiveModelSerializers.config.key_transform.

    + +
    = :camel_lower
    + +
    Adapter default
    + +

    Each adapter has a default transform configured:

    + +

    | Adapter | Default Key Transform | |—-|—-| | Json | +:unaltered | | JsonApi | :dash |

    +
    + + + + + \ No newline at end of file diff --git a/file.logging.html b/file.logging.html new file mode 100644 index 00000000..83867017 --- /dev/null +++ b/file.logging.html @@ -0,0 +1,88 @@ + + + + + + File: logging + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Logging

    + +

    The default logger in a Rails application will be +Rails.logger.

    + +

    When there is no Rails.logger, the default logger is an +instance of ActiveSupport::TaggedLogging logging to STDOUT.

    + +

    You may customize the logger in an initializer, for example:

    + +
    ActiveModelSerializers.logger = Logger.new(STDOUT)
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.outside_controller_use.html b/file.outside_controller_use.html new file mode 100644 index 00000000..0a59d0b3 --- /dev/null +++ b/file.outside_controller_use.html @@ -0,0 +1,133 @@ + + + + + + File: outside_controller_use + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Using ActiveModelSerializers Outside Of A Controller

    + +

    Serializing a resource

    + +

    In ActiveModelSerializers versions 0.10 or later, serializing resources +outside of the controller context is fairly simple:

    + +
    # Create our resource
    +post = Post.create(title: "Sample post", body: "I love Active Model Serializers!")
    +
    +# Optional options parameters
    +options = {}
    +
    +# Create a serializable resource instance
    +serializable_resource = ActiveModelSerializers::SerializableResource.new(post, options)
    +
    +# Convert your resource into json
    +model_json = serializable_resource.as_json
    +
    + +

    Looking up the Serializer for a Resource

    + +

    If you want to retrieve a serializer for a specific resource, you can do +the following:

    + +
    # Create our resource
    +post = Post.create(title: "Another Example", body: "So much fun.")
    +
    +# Optional options parameters
    +options = {}
    +
    +# Retrieve the default serializer for posts
    +serializer = ActiveModel::Serializer.serializer_for(post, options)
    +
    + +

    You could also retrieve the serializer via:

    + +
    ActiveModelSerializers::SerializableResource.new(post, options).serializer
    +
    + +

    Both approaches will return an instance, if any, of the resource's +serializer.

    + +

    Serializing before controller render

    + +

    At times, you might want to use a serializer without rendering it to the +view. For those cases, you can create an instance of +ActiveModelSerializers::SerializableResource with the resource +you want to be serialized and call .as_json.

    + +
    def create
    +  message = current_user.messages.create!(message_params)
    +  message_json = ActiveModelSerializers::SerializableResource.new(message).as_json
    +  MessageCreationWorker.perform(message_json)
    +  head 204
    +end
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.passing_arbitrary_options.html b/file.passing_arbitrary_options.html new file mode 100644 index 00000000..85071be2 --- /dev/null +++ b/file.passing_arbitrary_options.html @@ -0,0 +1,104 @@ + + + + + + File: passing_arbitrary_options + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Passing Arbitrary Options To A Serializer

    + +

    In addition to the serialization_scope, any options +passed to render that are not reserved for the adapter are available in +the serializer as instance_options.

    + +

    For example, we could pass in a field, such as user_id into +our serializer.

    + +
    # posts_controller.rb
    +class PostsController < ApplicationController
    +  def dashboard  
    +    render json: @post, user_id: 12
    +  end
    +end
    +
    +# post_serializer.rb
    +class PostSerializer < ActiveModel::Serializer
    +  attributes :id, :title, :body
    +
    +  def comments_by_me  
    +    Comments.where(user_id: instance_options[:user_id], post_id: object.id)
    +  end
    +end
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.rendering.html b/file.rendering.html new file mode 100644 index 00000000..9b3593e5 --- /dev/null +++ b/file.rendering.html @@ -0,0 +1,333 @@ + + + + + + File: rendering + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Rendering

    + +

    Implicit Serializer

    + +

    In your controllers, when you use render :json, Rails will now +first search for a serializer for the object and use it if available.

    + +
    class PostsController < ApplicationController
    +  def show
    +    @post = Post.find(params[:id])
    +
    +    render json: @post
    +  end
    +end
    +
    + +

    In this case, Rails will look for a serializer named +PostSerializer, and if it exists, use it to serialize the +Post.

    + +

    Explicit Serializer

    + +

    If you wish to use a serializer other than the default, you can explicitly +pass it to the renderer.

    + +

    1. For a resource:

    + +
    render json: @post, serializer: PostPreviewSerializer
    +
    + +

    2. For a resource collection:

    + +

    Specify the serializer for each resource with each_serializer

    + +
    render json: @posts, each_serializer: PostPreviewSerializer
    +
    + +

    The default serializer for collections is +CollectionSerializer.

    + +

    Specify the collection serializer with the serializer option.

    + +
    render json: @posts, serializer: CollectionSerializer, each_serializer: PostPreviewSerializer
    +
    + +

    Serializing non-ActiveRecord objects

    + +

    All serializable resources must pass the ActiveModel::Serializer::Lint::Tests.

    + +

    See the ActiveModelSerializers::Model for a base class that implements the +full API for a plain-old Ruby object (PORO).

    + +

    SerializableResource options

    + +

    The options hash passed to render or +ActiveModelSerializers::SerializableResource.new(resource, +options) are partitioned into serializer_opts and +adapter_opts. adapter_opts are passed to new +Adapters; serializer_opts are passed to new Serializers.

    + +

    The adapter_opts are specified in ActiveModelSerializers::SerializableResource::ADAPTER_OPTIONS. +The serializer_opts are the remaining options.

    + +

    (In Rails, the options are also passed to the +as_json(options) or to_json(options) methods on +the resource serialization by the Rails JSON renderer. They are, therefore, +important to know about, but not part of ActiveModelSerializers.)

    + +

    See ARCHITECTURE for more information.

    + +

    adapter_opts

    + +

    fields

    + +

    PR please :)

    + +

    adapter

    + +

    PR please :)

    + +

    key_transform

    + +
    json: posts, each_serializer: PostSerializer, key_transform: :camel_lower
    + +

    See Key Transforms for more informaiton.

    + +

    meta

    + +

    A meta member can be used to include non-standard +meta-information. meta can be utilized in several levels in a +response.

    + +
    Top-level
    + +

    To set top-level meta in a response, specify it in the +render call.

    + +
    render json: @post, meta: { total: 10 }
    +
    + +

    The key can be customized using meta_key option.

    + +
    render json: @post, meta: { total: 10 }, meta_key: "custom_meta"
    +
    + +

    meta will only be included in your response if you are using +an Adapter that supports root, e.g., JsonApi and +Json adapters. The default adapter, Attributes +does not have root.

    + +
    Resource-level
    + +

    To set resource-level meta in a response, define meta in a +serializer with one of the following methods:

    + +

    As a single, static string.

    + +
    meta stuff: 'value'
    +
    + +

    As a block containing a Hash.

    + +
    meta do
    +  {
    +    rating: 4,
    +    comments_count: object.comments.count
    +  }
    +end
    +
    + + + +

    If you wish to use Rails url helpers for link generation, e.g., +link(:resources) { resources_url }, ensure your application +sets Rails.application.routes.default_url_options.

    + +
    Top-level
    + +

    JsonApi supports a links object to be +specified at top-level, that you can specify in the render:

    + +
    links_object = {
    +    href: "http://example.com/api/posts",
    +    meta: {
    +      count: 10
    +    }
    +  }
    +  render json: @posts, links: links_object
    +
    + +

    That's the result:

    + +
    {
    +  "data": [
    +    {
    +      "type": "posts",
    +      "id": "1",
    +      "attributes": {
    +        "title": "JSON API is awesome!",
    +        "body": "You should be using JSON API",
    +        "created": "2015-05-22T14:56:29.000Z",
    +        "updated": "2015-05-22T14:56:28.000Z"
    +      }
    +    }
    +  ],
    +  "links": {
    +    "href": "http://example.com/api/posts",
    +    "meta": {
    +      "count": 10
    +    }
    +  }
    +}
    +
    + +

    This feature is specific to JsonApi, so you have to use the use the JsonApi Adapter

    + +
    Resource-level
    + +

    In your serializer, define each link in one of the following methods:

    + +

    As a static string

    + +
    link :link_name, 'https://example.com/resource'
    +
    + +

    As a block to be evaluated. When using Rails, URL helpers are available. +Ensure your application sets +Rails.application.routes.default_url_options.

    + +
    link :link_name_ do
    +  "https://example.com/resource/#{object.id}"
    +end
    +
    +link(:link_name) { "https://example.com/resource/#{object.id}" }
    +
    +link(:link_name) { resource_url(object) }
    +
    +link(:link_name) { url_for(controller: 'controller_name', action: 'index', only_path: false) }
    +
    + +

    serializer_opts

    + +

    include

    + +

    PR please :)

    + +

    Overriding the root key

    + +

    Overriding the resource root only applies when using the JSON adapter.

    + +

    Normally, the resource root is derived from the class name of the resource +being serialized. e.g. UserPostSerializer.new(UserPost.new) +will be serialized with the root user_post or +user_posts according the adapter collection pluralization +rules.

    + +

    When using the JSON adapter in your initializer +(ActiveModelSerializers.config.adapter = :json), or passing in the adapter +in your render call, you can specify the root by passing it as an argument +to render. For example:

    + +
    render json: @user_post, root: "admin_post", adapter: :json
    +
    + +

    This will be rendered as: json { "admin_post": { +"title": "how to do open source" } } +Note: the Attributes adapter (default) does not include a +resource root. You also will not be able to create a single top-level root +if you are using the :json_api adapter.

    + +

    serializer

    + +

    PR please :)

    + +

    scope

    + +

    PR please :)

    + +

    scope_name

    + +

    PR please :)

    + +

    Using a serializer without render

    + +

    See Usage +outside of a controller.

    + +

    Pagination

    + +

    See How +to add pagination links.

    +
    + + + + + \ No newline at end of file diff --git a/file.schema.html b/file.schema.html new file mode 100644 index 00000000..9fc5fd55 --- /dev/null +++ b/file.schema.html @@ -0,0 +1,347 @@ + + + + + + File: schema + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    + +

    JSON API Requests

    + + +

    Headers:

    +
    • +

      Request: Accept: application/vnd.api+json

      +
    • +

      Response: Content-Type: application/vnd.api+json

      +
    + +

    Fetching Data

    + +

    A server MUST support fetching resource data for every URL provided as:

    +
    • +

      a self link as part of the top-level links object

      +
    • +

      a self link as part of a resource-level links object

      +
    • +

      a related link as part of a relationship-level links object

      +
    + +

    Example supported requests

    + + +

    CRUD Actions

    + +

    Asynchronous Processing

    + +

    Bulk Operations Extension

    + +

    JSON API Document Schema

    + +

    | JSON API object | JSON API properties | Required | ActiveModelSerializers +representation | +|———————–|—————————————————————————————————-|———-|—————————————| | schema | +oneOf (success, failure, info) | | | success | data, included, meta, links, +jsonapi | | AM::SerializableResource | success.meta | meta | | +AMS::Adapter::Base#meta | success.included | UniqueArray(resource) | | +AMS::Adapter::JsonApi#serializable_hash_for_collection | success.data | +data | | | success.links | allOf (links, pagination) | | +AMS::Adapter::JsonApi#links_for | success.jsonapi | jsonapi | | | failure | +errors, meta, jsonapi | errors | AMS::Adapter::JsonApi#failure_document, +#1004 | failure.errors | UniqueArray(error) | | AM::S::ErrorSerializer, +#1004 | meta | Object | | | data | oneOf (resource, UniqueArray(resource)) +| | +AMS::Adapter::JsonApi#serializable_hash_for_collection,#serializable_hash_for_single_resource +| resource | String(type), String(id),
    attributes, +relationships,
    links, meta | type, id | +AM::S::Adapter::JsonApi#primary_data_for | links | Uri(self), Link(related) +| | #1028, #1246, #1282 | link | oneOf (linkString, linkObject) | | | +link.linkString | Uri | | | link.linkObject | Uri(href), meta | href | | +attributes | patternProperties(
    “^(?!relationships$|links$)\w
    *$"),
    any +valid JSON | | AM::Serializer#attributes, +AMS::Adapter::JsonApi#resource_object_for | relationships | patternProperties(
    ”^\w
    *$");
    links, +relationships.data, meta | | AMS::Adapter::JsonApi#relationships_for | +relationships.data | oneOf (relationshipToOne, relationshipToMany) | | +AMS::Adapter::JsonApi#resource_identifier_for | relationshipToOne | +anyOf(empty, linkage) | | | relationshipToMany | UniqueArray(linkage) | | | +empty | null | | | linkage | String(type), String(id), meta | type, id | +AMS::Adapter::JsonApi#primary_data_for | pagination | pageObject(first), +pageObject(last),
    pageObject(prev), pageObject(next) | | +AMS::Adapter::JsonApi::PaginationLinks#serializable_hash | +pagination.pageObject | oneOf(Uri, null) | | | jsonapi | String(version), +meta | | AMS::Adapter::JsonApi::Jsonapi#as_json | error | String(id), +links, String(status),
    String(code), String(title),
    String(detail), +error.source, meta | | AM::S::ErrorSerializer, +AMS::Adapter::JsonApi::Error.resource_errors | error.source | +String(pointer), String(parameter) | | +AMS::Adapter::JsonApi::Error.error_source | pointer | JSON Pointer RFC6901 | | +AMS::JsonPointer

    + +

    The jsonapi.org/schema makes a nice +roadmap.

    + +

    Success Document

    +
    • +

      [ ] success

      +
    • +

      [ ] data: "$ref": "#/definitions/data"

      +
    • +

      [ ] included: array of unique items of type "$ref": +"#/definitions/resource"

      +
    • +

      [ ] meta: "$ref": "#/definitions/meta"

      +
    • +

      [ ] links:

      +
      • +

        [ ] link: "$ref": "#/definitions/links"

        +
      • +

        [ ] pagination: "$ref": +"#/definitions/pagination"

        +
      +
    • +

      [ ] jsonapi: "$ref": +"#/definitions/jsonapi"

      +
    + +

    Failure Document

    +
    • +

      [ ] failure

      +
    • +

      [x] errors: array of unique items of type "$ref": +"#/definitions/error"

      +
    • +

      [ ] meta: "$ref": "#/definitions/meta"

      +
    • +

      [ ] jsonapi: "$ref": +"#/definitions/jsonapi"

      +
    + +

    Info Document

    +
    • +

      [ ] info

      +
    • +

      [ ] meta: "$ref": "#/definitions/meta"

      +
    • +

      [ ] links: "$ref": "#/definitions/links"

      +
    • +

      [ ] jsonapi: "$ref": +"#/definitions/jsonapi"

      +
    + +

    Definitions

    +
    • +

      [ ] definitions:

      +
    • +

      [ ] meta

      +
    • +

      [ ] data: oneOf (resource, array of unique resources)

      +
    • +

      [ ] resource

      +
      • +

        [ ] attributes

        +
      • +

        [ ] relationships

        +
      • +

        [ ] relationshipToOne

        +
        • +

          [ ] empty

          +
        • +

          [ ] linkage

          +
        • +

          [ ] meta

          +
        +
      • +

        [ ] relationshipToMany

        +
        • +

          [ ] linkage

          +
        • +

          [ ] meta

          +
        +
      • +

        [ ] links

        +
      • +

        [ ] meta

        +
      +
    • +

      [ ] links

      +
      • +

        [ ] link

        +
      • +

        [ ] uri

        +
      • +

        [ ] href, meta

        +
      +
    • +

      [ ] pagination

      +
    • +

      [ ] jsonapi

      +
      • +

        [ ] meta

        +
      +
    • +

      [ ] error

      +
      • +

        [ ] id: a unique identifier for this particular occurrence of the problem.

        +
      • +

        [ ] links: a links object containing the following members:

        +
      • +

        [ ] about: a link that leads to further details about this particular +occurrence of the problem.

        +
      • +

        [ ] status: the HTTP status code applicable to this problem, expressed as a +string value.

        +
      • +

        [ ] code: an application-specific error code, expressed as a string value.

        +
      • +

        [ ] title: a short, human-readable summary of the problem that SHOULD NOT +change from occurrence to occurrence of the problem, except for purposes of +localization.

        +
      • +

        [x] detail: a human-readable explanation specific to this occurrence of the +problem.

        +
      • +

        [x] source: an object containing references to the source of the error, +optionally including any of the following members:

        +
      • +

        [x] pointer: a JSON Pointer RFC6901 to the associated +entity in the request document [e.g. “/data” for a primary data object, or +“/data/attributes/title” for a specific attribute].

        +
      • +

        [x] parameter: a string indicating which query parameter caused the error.

        +
      • +

        [ ] meta: a meta object containing non-standard meta-information about the +error.

        +
      +
    +
    + + + + + \ No newline at end of file diff --git a/file.serialize_poro.html b/file.serialize_poro.html new file mode 100644 index 00000000..22657e43 --- /dev/null +++ b/file.serialize_poro.html @@ -0,0 +1,102 @@ + + + + + + File: serialize_poro + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    How to serialize a Plain-Old Ruby Object (PORO)

    + +

    When you are first getting started with ActiveModelSerializers, it may seem +only ActiveRecord::Base objects can be serializable, but +pretty much any object can be serializable with ActiveModelSerializers. +Here is an example of a PORO that is serializable: “`ruby

    + +

    my_model.rb

    + +

    class MyModel alias :read_attribute_for_serialization :send attr_accessor +:id, :name, :level

    + +

    def initialize(attributes) @id = attributes @name = attributes @level = attributes end

    + +

    def self.model_name @_model_name ||= ActiveModel::Name.new(self) end end +“`

    + +

    Fortunately, ActiveModelSerializers provides a ActiveModelSerializers::Model +which you can use in production code that will make your PORO a lot +cleaner. The above code now becomes: ruby # my_model.rb class MyModel +< ActiveModelSerializers::Model attr_accessor :id, :name, :level end +

    + +

    The default serializer would be MyModelSerializer.

    +
    + + + + + \ No newline at end of file diff --git a/file.serializers.html b/file.serializers.html new file mode 100644 index 00000000..018cb777 --- /dev/null +++ b/file.serializers.html @@ -0,0 +1,503 @@ + + + + + + File: serializers + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    Back to Guides

    + +

    Serializers

    + +

    Given a serializer class:

    + +
    class SomeSerializer < ActiveModel::Serializer
    +end
    +
    + +

    The following methods may be defined in it:

    + +

    Attributes

    + +

    ::attributes

    + +

    Serialization of the resource title and body

    + +

    | In Serializer | #attributes | |—————————- |————-| | attributes +:title, :body | { title: 'Some Title', body: 'Some +Body' } | attributes :title, :body
    def +body "Special #{object.body}" end | { title: +'Some Title', body: 'Special Some Body' }

    + +

    ::attribute

    + +

    Serialization of the resource title

    + +

    | In Serializer | #attributes | |—————————- |————-| | attribute +:title | { title: 'Some Title' } | +attribute :title, key: :name | { name: 'Some +Title' } | attribute :title { 'A Different +Title'} | { title: 'A Different Title' } | +attribute :title
    def title 'A Different +Title' end | { title: 'A Different Title' }

    + +

    An if or unless option can make an attribute +conditional. It takes a symbol of a method name on the serializer, or a +lambda literal.

    + +

    e.g.

    + +
    attribute :private_data, if: :is_current_user?
    +attribute :another_private_data, if: -> { scope.admin? }
    +
    +def is_current_user?
    +  object.id == current_user.id
    +end
    +
    + +

    Associations

    + +

    The interface for associations is, generically:

    + +
    +

    association_type(association_name, options, &block)

    +
    + +

    Where:

    +
    • +

      association_type may be has_one, +has_many, belongs_to.

      +
    • +

      association_name is a method name the serializer calls.

      +
    • +

      optional: options may be:

      +
    • +

      key: The name used for the serialized association.

      +
    • +

      serializer:

      +
    • +

      if:

      +
    • +

      unless:

      +
    • +

      virtual_value:

      +
    • +

      polymorphic: defines if polymorphic relation type should be +nested in serialized association.

      +
    • +

      optional: &block is a context that returns the +association's attributes.

      +
    • +

      prevents association_name method from being called.

      +
    • +

      return value of block is used as the association value.

      +
    • +

      yields the serializer to the block.

      +
    • +

      include_data false prevents the data key from +being rendered in the JSON API relationship.

      +
    + +

    ::has_one

    + +

    e.g.

    + +
    has_one :bio
    +has_one :blog, key: :site
    +has_one :maker, virtual_value: { id: 1 }
    +
    +has_one :blog do |serializer|
    +  serializer.cached_blog
    +end
    +
    +def cached_blog
    +  cache_store.fetch("cached_blog:#{object.updated_at}") do
    +    Blog.find(object.blog_id)
    +  end
    +end
    +
    + +
    has_one :blog, if: :show_blog?
    +# you can also use a string or lambda
    +# has_one :blog, if: 'scope.admin?'
    +# has_one :blog, if: -> (serializer) { serializer.scope.admin? }
    +# has_one :blog, if: -> { scope.admin? }
    +
    +def show_blog?
    +  scope.admin?
    +end
    +
    + +

    ::has_many

    + +

    e.g.

    + +
    has_many :comments
    +has_many :comments, key: :reviews
    +has_many :comments, serializer: CommentPreviewSerializer
    +has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
    +has_many :comments, key: :last_comments do
    +  last(1)
    +end
    +
    + +

    ::belongs_to

    + +

    e.g.

    + +
    belongs_to :author, serializer: AuthorPreviewSerializer
    +belongs_to :author, key: :writer
    +belongs_to :post
    +belongs_to :blog
    +def blog
    +  Blog.new(id: 999, name: 'Custom blog')
    +end
    +
    + +

    Polymorphic Relationships

    + +

    Polymorphic relationships are serialized by specifying the relationship, +like any other association. For example:

    + +
    class PictureSerializer < ActiveModel::Serializer
    +  has_one :imageable
    +end
    +
    + +

    For more context, see the tests for each adapter.

    + +

    Caching

    + +

    ::cache

    + +

    e.g.

    + +
    cache key: 'post', expires_in: 0.1, skip_digest: true
    +cache expires_in: 1.day, skip_digest: true
    +cache key: 'writer', skip_digest: true
    +cache only: [:name], skip_digest: true
    +cache except: [:content], skip_digest: true
    +cache key: 'blog'
    +cache only: [:id]
    +
    + +

    #cache_key

    + +

    e.g.

    + +
    # Uses a custom non-time-based cache key
    +def cache_key
    +  "#{self.class.name.downcase}/#{self.id}"
    +end
    +
    + +

    Other

    + +

    ::type

    + +

    The ::type method defines the JSONAPI type +that will be rendered for this serializer. It either takes a +String or Symbol as parameter.

    + +

    Note: This method is useful only when using the :json_api +adapter.

    + +

    Examples: ruby class UserProfileSerializer < +ActiveModel::Serializer type 'profile' end class +AuthorProfileSerializer < ActiveModel::Serializer type :profile end +

    + +

    With the :json_api adapter, the previous serializers would be +rendered as:

    + +
    {
    +  "data": {
    +    "id": "1",
    +    "type": "profile"
    +  }
    +}
    +
    + + + +
    link :self do
    +  href "https://example.com/link_author/#{object.id}"
    +end
    +link :author { link_author_url(object) }
    +link :link_authors { link_authors_url }
    +link :other, 'https://example.com/resource'
    +link :posts { link_author_posts_url(object) }
    +
    + +

    #object

    + +

    The object being serialized.

    + +

    #root

    + +

    PR please :)

    + +

    #scope

    + +

    Allows you to include in the serializer access to an external method.

    + +

    It's intended to provide an authorization context to the serializer, so +that you may e.g. show an admin all comments on a post, else only published +comments.

    +
    • +

      scope is a method on the serializer instance that comes from +options[:scope]. It may be nil.

      +
    • +

      scope_name is an option passed to the new serializer +(options[:scope_name]). The serializer defines a method with +that name that calls the scope, e.g. def current_user; +scope; end. Note: it does not define the method if the serializer +instance responds to it.

      +
    + +

    That's a lot of words, so here's some examples:

    + +

    First, let's assume the serializer is instantiated in the controller, +since that's the usual scenario. We'll refer to the serialization +context as controller.

    + +

    | options | Serializer#scope | method definition | |——– | +——————|——————–| | scope: current_user, scope_name: +:current_user | current_user | +Serializer#current_user calls +controller.current_user | scope: view_context, +scope_name: :view_context | view_context | +Serializer#view_context calls +controller.view_context

    + +

    We can take advantage of the scope to customize the objects returned based +on the current user (scope).

    + +

    For example, we can limit the posts the current user sees to those they +created:

    + +
    class PostSerializer < ActiveModel::Serializer
    +  attributes :id, :title, :body
    +
    +  # scope comments to those created_by the current user
    +  has_many :comments do
    +    object.comments.where(created_by: current_user)
    +  end
    +end
    +
    + +

    Whether you write the method as above or as +object.comments.where(created_by: scope) is a matter of +preference (assuming scope_name has been set).

    + +
    Controller Authorization Context
    + +

    In the controller, the scope/scope_name options are equal to the serialization_scopemethod, +which is :current_user, by default.

    + +

    Specifically, the scope_name is defaulted to +:current_user, and may be set as serialization_scope +:view_context. The scope is set to +send(scope_name) when scope_name is present and +the controller responds to scope_name.

    + +

    Thus, in a serializer, the controller provides current_user as +the current authorization scope when you call render :json.

    + +

    IMPORTANT: Since the scope is set at render, you may want +to customize it so that current_user isn't called on every +request. This was also +a problem in 0.9.

    + +

    We can change the scope from current_user to +view_context.

    + +
    class SomeController < ActionController::Base
    ++  serialization_scope :view_context
    +
    +  def current_user
    +    User.new(id: 2, name: 'Bob', admin: true)
    +  end
    +
    +  def edit
    +    user = User.new(id: 1, name: 'Pete')
    +    render json: user, serializer: AdminUserSerializer, adapter: :json_api
    +  end
    +end
    + +

    We could then use the controller method view_context in our +serializer, like so:

    + +
    class AdminUserSerializer < ActiveModel::Serializer
    +  attributes :id, :name, :can_edit
    +
    +  def can_edit?
    ++    view_context.current_user.admin?
    +  end
    +end
    +
    + +

    So that when we render the #edit action, we'll get

    + +
    {"data":{"id":"1","type":"users","attributes":{"name":"Pete","can_edit":true}}}
    +
    + +

    Where can_edit is +view_context.current_user.admin? (true).

    + +

    #read_attribute_for_serialization(key)

    + +

    The serialized value for a given key. e.g. +read_attribute_for_serialization(:title) #=> 'Hello +World'

    + + + +

    PR please :)

    + +

    #json_key

    + +

    PR please :)

    + +

    Examples

    + +

    Given two models, a Post(title: string, body: text) and a +Comment(name: string, body: text, post_id: integer), you will +have two serializers:

    + +
    class PostSerializer < ActiveModel::Serializer
    +  cache key: 'posts', expires_in: 3.hours
    +  attributes :title, :body
    +
    +  has_many :comments
    +end
    +
    + +

    and

    + +
    class CommentSerializer < ActiveModel::Serializer
    +  attributes :name, :body
    +
    +  belongs_to :post
    +end
    +
    + +

    Generally speaking, you, as a user of ActiveModelSerializers, will write +(or generate) these serializer classes.

    + +

    More Info

    + +

    For more information, see the +Serializer class on GitHub

    + +

    Overriding association methods

    + +

    To override an association, call has_many, +has_one or belongs_to with a block:

    + +
    class PostSerializer < ActiveModel::Serializer
    +  has_many :comments do
    +    object.comments.active
    +  end
    +end
    +
    + +

    Overriding attribute methods

    + +

    To override an attribute, call attribute with a block:

    + +
    class PostSerializer < ActiveModel::Serializer
    +  attribute :body do
    +    object.body.downcase
    +  end
    +end
    +
    + +

    Overriding association serializer lookup

    + +

    If you want to define a specific serializer lookup for your associations, +you can override the ActiveModel::Serializer.serializer_for +method to return a serializer class based on defined conditions.

    + +
    class MySerializer < ActiveModel::Serializer
    +  def self.serializer_for(model, options)
    +    return SparseAdminSerializer if model.class == 'Admin'
    +    super
    +  end
    +
    +  # the rest of the serializer
    +end
    +
    +
    + + + + + \ No newline at end of file diff --git a/file.template.html b/file.template.html new file mode 100644 index 00000000..51152e87 --- /dev/null +++ b/file.template.html @@ -0,0 +1,94 @@ + + + + + + File: template + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    + +

    Summary

    + +

    Motivation

    + +

    Detailed design

    + +

    Drawbacks

    + +

    Alternatives

    + +

    Unresolved questions

    +
    + + + + + \ No newline at end of file diff --git a/file.test.html b/file.test.html new file mode 100644 index 00000000..4a3f65c1 --- /dev/null +++ b/file.test.html @@ -0,0 +1,222 @@ + + + + + + File: test + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
    +

    How to test

    + +

    Controller Serializer Usage

    + +

    ActiveModelSerializers provides a assert_serializer method to +be used on your controller tests to assert that a specific serializer was +used.

    + +
    class PostsControllerTest < ActionController::TestCase
    +  test "should render post serializer" do
    +    get :index
    +    assert_serializer "PostSerializer"
    +  end
    +end
    +
    + +

    See ActiveModelSerializers::Test::Serializer +for more examples and documentation.

    + +

    Serialization against a schema

    + +

    Dependencies

    + +

    To use the assert_response_schema you need to have the json_schema on your +Gemfile. Please add it to your Gemfile and run $ bundle +install.

    + +

    Minitest test helpers

    + +

    ActiveModelSerializers provides a assert_response_schema +method to be used on your controller tests to assert the response against a +JSON Schema. Let's take a look in +an example.

    + +
    class PostsController < ApplicationController
    +  def show
    +    @post = Post.find(params[:id])
    +
    +    render json: @post
    +  end
    +end
    +
    + +

    To test the posts#show response of this controller we need to +create a file named test/support/schemas/posts/show.json. The +helper uses a naming convention to locate the file.

    + +

    This file is a JSON Schema representation of our response.

    + +
    {
    +  "properties": {
    +    "title" : { "type" : "string" },
    +    "content" : { "type" : "string" }
    +  }
    +}
    + +

    With all in place we can go to our test and use the helper.

    + +
    class PostsControllerTest < ActionController::TestCase
    +  test "should render right response" do
    +    get :index
    +    assert_response_schema
    +  end
    +end
    +
    + +

    Load a custom schema

    + +

    If we need to use another schema, for example when we have a namespaced API +that shows the same response, we can pass the path of the schema.

    + +
    module V1
    +  class PostsController < ApplicationController
    +    def show
    +      @post = Post.find(params[:id])
    +
    +      render json: @post
    +    end
    +  end
    +end
    +
    + +
    class V1::PostsControllerTest < ActionController::TestCase
    +  test "should render right response" do
    +    get :index
    +    assert_response_schema('posts/show.json')
    +  end
    +end
    +
    + +

    Change the schema path

    + +

    By default all schemas are created at test/support/schemas. If +we are using RSpec for example we can change this to +spec/support/schemas defining the default schema path in an +initializer.

    + +
    ActiveModelSerializers.config.schema_path = 'spec/support/schemas'
    +
    + +

    Using with the Heroku’s JSON Schema-based tools

    + +

    To use the test helper with the prmd and committee.

    + +

    We need to change the schema path to the recommended by prmd:

    + +
    ActiveModelSerializers.config.schema_path = 'docs/schema/schemata'
    +
    + +

    We also need to structure our schemata according to Heroku's +conventions (e.g. including required +metadata and links.

    + +

    JSON Pointers

    + +

    If we plan to use JSON +Pointers we need to define the id attribute on the schema. +Example:

    + +
    // attributes.json
    +
    +{
    +  "id": "file://attributes.json#",
    +  "properties": {
    +    "name" : { "type" : "string" },
    +    "description" : { "type" : "string" }
    +  }
    +}
    + +
    // show.json
    +
    +{
    +  "properties": {
    +    "name": {
    +      "$ref": "file://attributes.json#/properties/name"
    +    },
    +    "description": {
    +      "$ref": "file://attributes.json#/properties/description"
    +    }
    +  }
    +}
    +
    + + + + + \ No newline at end of file diff --git a/file_list.html b/file_list.html index 6bf67e5a..d9febc30 100644 --- a/file_list.html +++ b/file_list.html @@ -54,6 +54,72 @@
  • README
  • +
  • adapters
  • + + +
  • caching
  • + + +
  • configuration_options
  • + + +
  • deserialization
  • + + +
  • getting_started
  • + + +
  • instrumentation
  • + + +
  • key_transforms
  • + + +
  • logging
  • + + +
  • rendering
  • + + +
  • serializers
  • + + +
  • add_pagination_links
  • + + +
  • add_root_key
  • + + +
  • outside_controller_use
  • + + +
  • passing_arbitrary_options
  • + + +
  • serialize_poro
  • + + +
  • test
  • + + +
  • ember-and-json-api
  • + + +
  • grape
  • + + +
  • errors
  • + + +
  • schema
  • + + +
  • 0000-namespace
  • + + +
  • template
  • + + diff --git a/index.html b/index.html index 0c888667..dbfa707b 100644 --- a/index.html +++ b/index.html @@ -253,7 +253,7 @@ information.

    diff --git a/top-level-namespace.html b/top-level-namespace.html index 6fb5ca22..9310c3c2 100644 --- a/top-level-namespace.html +++ b/top-level-namespace.html @@ -105,7 +105,7 @@