mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Meta no longer handled in Base adapter.
This commit is contained in:
@@ -48,11 +48,6 @@ module ActiveModelSerializers
|
||||
Attributes.new(association.serializer, opts).serializable_hash(options)
|
||||
end
|
||||
|
||||
# no-op: Attributes adapter does not include meta data, because it does not support root.
|
||||
def include_meta(json)
|
||||
json
|
||||
end
|
||||
|
||||
# Set @cached_attributes
|
||||
def cache_attributes
|
||||
return if @cached_attributes.present?
|
||||
|
||||
@@ -26,9 +26,7 @@ module ActiveModelSerializers
|
||||
end
|
||||
|
||||
def as_json(options = nil)
|
||||
hash = serializable_hash(options)
|
||||
include_meta(hash)
|
||||
hash
|
||||
serializable_hash(options)
|
||||
end
|
||||
|
||||
def fragment_cache(cached_hash, non_cached_hash)
|
||||
@@ -49,23 +47,10 @@ module ActiveModelSerializers
|
||||
options ||= {} # rubocop:disable Lint/UselessAssignment
|
||||
end
|
||||
|
||||
def meta
|
||||
instance_options.fetch(:meta, nil)
|
||||
end
|
||||
|
||||
def meta_key
|
||||
instance_options.fetch(:meta_key, 'meta'.freeze)
|
||||
end
|
||||
|
||||
def root
|
||||
serializer.json_key.to_sym if serializer.json_key
|
||||
end
|
||||
|
||||
def include_meta(json)
|
||||
json[meta_key] = meta unless meta.blank?
|
||||
json
|
||||
end
|
||||
|
||||
class << self
|
||||
# Sets the default transform for the adapter.
|
||||
#
|
||||
|
||||
@@ -4,8 +4,18 @@ module ActiveModelSerializers
|
||||
def serializable_hash(options = nil)
|
||||
options = serialization_options(options)
|
||||
serialized_hash = { root => Attributes.new(serializer, instance_options).serializable_hash(options) }
|
||||
serialized_hash[meta_key] = meta unless meta.blank?
|
||||
|
||||
self.class.transform_key_casing!(serialized_hash, instance_options)
|
||||
end
|
||||
|
||||
def meta
|
||||
instance_options.fetch(:meta, nil)
|
||||
end
|
||||
|
||||
def meta_key
|
||||
instance_options.fetch(:meta_key, 'meta'.freeze)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,6 +67,7 @@ module ActiveModelSerializers
|
||||
# links: toplevel_links,
|
||||
# jsonapi: toplevel_jsonapi
|
||||
# }.reject! {|_,v| v.nil? }
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def success_document
|
||||
is_collection = serializer.respond_to?(:each)
|
||||
serializers = is_collection ? serializer : [serializer]
|
||||
@@ -130,8 +131,11 @@ module ActiveModelSerializers
|
||||
hash[:links].update(pagination_links_for(serializer))
|
||||
end
|
||||
|
||||
hash[:meta] = instance_options[:meta] if instance_options[:meta].is_a?(Hash)
|
||||
|
||||
hash
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
|
||||
# {http://jsonapi.org/format/#errors JSON API Errors}
|
||||
# TODO: look into caching
|
||||
|
||||
Reference in New Issue
Block a user