Skip to content

Commit

Permalink
Renaming Error to NoSerializerError
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomdmoura committed Jun 22, 2015
1 parent 3d98c3c commit 40c4183
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/action_controller/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def use_adapter?
@_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

Expand Down
8 changes: 1 addition & 7 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,7 @@ def each_association(&block)
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
Expand Down
6 changes: 3 additions & 3 deletions lib/active_model/serializer/array_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,7 @@ def initialize(objects, options = {})
)

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
Expand Down

0 comments on commit 40c4183

Please sign in to comment.