From 5ae45688e35bd84ec7952ace1e96996a6852539a Mon Sep 17 00:00:00 2001 From: Benjamin Kiah Stroud <32469930+bkiahstroud@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:41:04 -0700 Subject: [PATCH] avoid false positive from .try(:internal_resource) Using #try on :internal_resource can yield unexpected results. If the method is undefined, it can return a truthy value instead of the typical nil. E.g. ```ruby Hyrax::FileSet.try(:internal_resource) || 'hi' => #> ``` --- lib/bulkrax.rb | 53 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/lib/bulkrax.rb b/lib/bulkrax.rb index 883fe2a3..948c8c58 100644 --- a/lib/bulkrax.rb +++ b/lib/bulkrax.rb @@ -98,7 +98,22 @@ def collection_model_class attr_writer :collection_model_class def collection_model_internal_resource - collection_model_class.try(:internal_resource) || collection_model_class.to_s + # WARN: Using #try on :internal_resource can yield unexpected results. + # If the method is undefined, it can return a truthy value instead of + # the typical nil. + # + # E.g. + # ```ruby + # Hyrax::FileSet.try(:internal_resource) || 'hi' + # => # # #