mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Rename FlattenJson to Attributes (allow plural adapter names)
This commit is contained in:
@@ -5,11 +5,11 @@ module ActiveModel
|
||||
ADAPTER_MAP = {}
|
||||
private_constant :ADAPTER_MAP if defined?(private_constant)
|
||||
extend ActiveSupport::Autoload
|
||||
autoload :Attributes
|
||||
autoload :Null
|
||||
autoload :FragmentCache
|
||||
autoload :Json
|
||||
autoload :JsonApi
|
||||
autoload :Null
|
||||
autoload :FlattenJson
|
||||
autoload :CachedSerializer
|
||||
|
||||
def self.create(resource, options = {})
|
||||
@@ -74,7 +74,8 @@ module ActiveModel
|
||||
# @api private
|
||||
def find_by_name(adapter_name)
|
||||
adapter_name = adapter_name.to_s.classify.tr('API', 'Api')
|
||||
ActiveModel::Serializer::Adapter.const_get(adapter_name.to_sym) or # rubocop:disable Style/AndOr
|
||||
"ActiveModel::Serializer::Adapter::#{adapter_name}".safe_constantize ||
|
||||
"ActiveModel::Serializer::Adapter::#{adapter_name.pluralize}".safe_constantize or # rubocop:disable Style/AndOr
|
||||
fail UnknownAdapterError
|
||||
end
|
||||
private :find_by_name
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class ActiveModel::Serializer::Adapter::FlattenJson < ActiveModel::Serializer::Adapter::Json
|
||||
class ActiveModel::Serializer::Adapter::Attributes < ActiveModel::Serializer::Adapter
|
||||
def serializable_hash(options = nil)
|
||||
options ||= {}
|
||||
if serializer.respond_to?(:each)
|
||||
result = serializer.map { |s| FlattenJson.new(s).serializable_hash(options) }
|
||||
result = serializer.map { |s| Attributes.new(s).serializable_hash(options) }
|
||||
else
|
||||
hash = {}
|
||||
|
||||
@@ -43,7 +43,7 @@ class ActiveModel::Serializer::Adapter::FlattenJson < ActiveModel::Serializer::A
|
||||
|
||||
private
|
||||
|
||||
# no-op: FlattenJson adapter does not include meta data, because it does not support root.
|
||||
# no-op: Attributes adapter does not include meta data, because it does not support root.
|
||||
def include_meta(json)
|
||||
json
|
||||
end
|
||||
@@ -4,7 +4,7 @@ class ActiveModel::Serializer::Adapter::Json < ActiveModel::Serializer::Adapter
|
||||
|
||||
def serializable_hash(options = nil)
|
||||
options ||= {}
|
||||
{ root => FlattenJson.new(serializer).serializable_hash(options) }
|
||||
{ root => Attributes.new(serializer).serializable_hash(options) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -6,7 +6,7 @@ module ActiveModel
|
||||
|
||||
included do |base|
|
||||
base.config.array_serializer = ActiveModel::Serializer::ArraySerializer
|
||||
base.config.adapter = :flatten_json
|
||||
base.config.adapter = :attributes
|
||||
base.config.jsonapi_resource_type = :plural
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user