lib/transmutation/serialization/lookup.rb in transmutation-0.2.3 vs lib/transmutation/serialization/lookup.rb in transmutation-0.3.0

- old
+ new

@@ -10,46 +10,40 @@ end # Bubbles up the namespace until we find a matching serializer. # # @see Transmutation::Serialization#lookup_serializer + # @note This never bubbles up the object's namespace, only the caller's namespace. # - # Example: - # + # @example # namespace: Api::V1::Admin::Detailed # serializer: Chat::User # # This method will attempt to find a serializer defined in the following order: # # - Api::V1::Admin::Detailed::Chat::UserSerializer # - Api::V1::Admin::Chat::UserSerializer # - Api::V1::Chat::UserSerializer # - Api::Chat::UserSerializer # - Chat::UserSerializer - # - # Note: This never bubbles up the object's namespace, only the caller's namespace. def serializer_for(object, serializer: nil) - return Transmutation::CollectionSerializer if object.respond_to?(:map) - serializer_name = serializer_name_for(object, serializer: serializer) return constantize_serializer!(Object, serializer_name, object: object) if serializer_name.start_with?("::") potential_namespaces.each do |potential_namespace| return potential_namespace.const_get(serializer_name) if potential_namespace.const_defined?(serializer_name) end - raise SerializerNotFound.new(@object, namespace: serializer_namespace, name: serializer_name) + raise SerializerNotFound.new(object, namespace: serializer_namespace, name: serializer_name) end # Returns the highest specificity serializer name for the given object. # # @param object [Object] The object to find the serializer name for. # # @return [String] The serializer name. def serializer_name_for(object, serializer: nil) - return "::Transmutation::CollectionSerializer" if object.respond_to?(:map) - "#{serializer&.delete_suffix("Serializer") || object.class.name}Serializer" end private