Skip to content

Commit

Permalink
Revert "Allow serializer_for to accept String instead of just class o…
Browse files Browse the repository at this point in the history
…bjects"

Ref: 460d4c5

I first thought about making it configurable, but I just can't find a
justification for this feature in a very stable gem with such backward
compatibility impact.
  • Loading branch information
byroot committed Apr 10, 2024
1 parent 5426bc3 commit aac72cf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ def build_serializer_class(resource, options)
klass_name = +""
klass_name << "#{options[:namespace]}::" if options[:namespace]
klass_name << options[:prefix].to_s.classify if options[:prefix]
if resource.is_a?(String)
klass_name << "#{resource}Serializer"
else
klass_name << "#{resource.class.name}Serializer"
end
klass_name << "#{resource.class.name}Serializer"
end

def associate(klass, *attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_serializer_for_array_returns_appropriate_type
def object.serializer_class; CustomSerializer; end

assert_equal CustomSerializer, Serializer.serializer_for(object)
assert_equal CustomSerializer, Serializer.serializer_for('Custom')
assert_nil Serializer.serializer_for('Custom')
end
end

Expand Down

0 comments on commit aac72cf

Please sign in to comment.