From 007e3eb6688c5ae53786d9cafa69ec41e6372c9d Mon Sep 17 00:00:00 2001 From: Matthias Viehweger Date: Fri, 6 Oct 2023 09:45:48 +0200 Subject: [PATCH] Allow for more sophisticated pluralization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While removing the dependency on ActiveSupport is good, it sometimes results in suboptimal results. Therefore, allow the hosting application to provide the String with a pluralize-method. This could come from ActiveSupport or a custom method, tailored towards the need of the application. If this method is not available, continue with the naïve implementation that works most of the time. --- lib/oat/adapters/json_api.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/oat/adapters/json_api.rb b/lib/oat/adapters/json_api.rb index 9c72515..1ef5857 100644 --- a/lib/oat/adapters/json_api.rb +++ b/lib/oat/adapters/json_api.rb @@ -150,6 +150,8 @@ def entity_without_root(obj, serializer_class = nil, &block) PLURAL = /s$/ def pluralize(str) + return str.pluralize if str.respond_to?(:pluralize) + if str =~ PLURAL str else