mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Renaming Error to NoSerializerError
This commit is contained in:
parent
e5d1e40dbd
commit
d3649d5b4e
@ -43,10 +43,10 @@ module ActionController
|
||||
@_serializer_opts[:scope_name] = _serialization_scope
|
||||
|
||||
begin
|
||||
object = serializer.new(resource, @_serializer_opts)
|
||||
rescue ActiveModel::Serializer::ArraySerializer::Error
|
||||
serialized = serializer.new(resource, @_serializer_opts)
|
||||
rescue ActiveModel::Serializer::ArraySerializer::NoSerializerError
|
||||
else
|
||||
resource = ActiveModel::Serializer::Adapter.create(object, @_adapter_opts)
|
||||
resource = ActiveModel::Serializer::Adapter.create(serialized, @_adapter_opts)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -211,13 +211,7 @@ module ActiveModel
|
||||
association_value,
|
||||
options.except(:serializer).merge(serializer_from_options(association_options))
|
||||
)
|
||||
rescue ActiveModel::Serializer::ArraySerializer::Error
|
||||
# 1. Failure to serialize an element in a collection, e.g. [ {hi: "Steve" } ] will fail
|
||||
# with NoMethodError when the ArraySerializer finds no serializer for the hash { hi: "Steve" },
|
||||
# and tries to call new on that nil.
|
||||
# 2. Convert association_value to hash using implicit as_json
|
||||
# 3. Set as virtual value (serializer is nil)
|
||||
# 4. Consider warning when this happens
|
||||
rescue ActiveModel::Serializer::ArraySerializer::NoSerializerError
|
||||
virtual_value = association_value
|
||||
virtual_value = virtual_value.as_json if virtual_value.respond_to?(:as_json)
|
||||
association_options[:association_options][:virtual_value] = virtual_value
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class ArraySerializer
|
||||
Error = Class.new(StandardError)
|
||||
NoSerializerError = Class.new(StandardError)
|
||||
include Enumerable
|
||||
delegate :each, to: :@objects
|
||||
|
||||
attr_reader :meta, :meta_key, :objects
|
||||
attr_reader :meta, :meta_key
|
||||
|
||||
def initialize(objects, options = {})
|
||||
@resource = objects
|
||||
@ -16,7 +16,7 @@ module ActiveModel
|
||||
)
|
||||
|
||||
if serializer_class.nil?
|
||||
fail Error, "No serializer found for object: #{object.inspect}"
|
||||
fail NoSerializerError, "No serializer found for object: #{object.inspect}"
|
||||
else
|
||||
serializer_class.new(object, options.except(:serializer))
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user