Add default_includes configuration

This is useful to set application-wide default behavior - e.g. in
previous versions of AMS the default behavior was to serialize the
full object graph by default - equivalent to the '**' include tree.

Currently just the global setting, but I think this could also work
on a per-serializer basis, with more attention.
This commit is contained in:
Ben Woosley
2016-01-12 12:05:11 -08:00
committed by Noah Silas
parent a701777bd5
commit 8c18d18cdb
7 changed files with 132 additions and 38 deletions

View File

@@ -10,8 +10,6 @@ module ActiveModel
module Associations
extend ActiveSupport::Concern
DEFAULT_INCLUDE_TREE = ActiveModel::Serializer::IncludeTree.from_string('*')
included do
with_options instance_writer: false, instance_reader: true do |serializer|
serializer.class_attribute :_reflections
@@ -80,10 +78,11 @@ module ActiveModel
end
end
# @param [IncludeTree] include_tree (defaults to all associations when not provided)
# @param [IncludeTree] include_tree (defaults to the
# default_includes config value when not provided)
# @return [Enumerator<Association>]
#
def associations(include_tree = DEFAULT_INCLUDE_TREE)
def associations(include_tree = ActiveModelSerializers.default_include_tree)
return unless object
Enumerator.new do |y|

View File

@@ -19,6 +19,7 @@ module ActiveModel
collection_serializer
end
config.default_includes = '*'
config.adapter = :attributes
config.jsonapi_resource_type = :plural
config.jsonapi_version = '1.0'