lib/bulkrax.rb in bulkrax-8.2.0 vs lib/bulkrax.rb in bulkrax-8.2.1
- old
+ new
@@ -96,30 +96,67 @@
end
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'
+ # => #<Dry::Types::Result::Failure input=:internal_resource error=...
+ # ```
+ if collection_model_class.respond_to?(:internal_resource)
+ collection_model_class.internal_resource
+ else
+ collection_model_class.to_s
+ end
end
def file_model_class
@file_model_class ||= defined?(::Hyrax) ? ::FileSet : File
end
attr_writer :file_model_class
def file_model_internal_resource
- file_model_class.try(:internal_resource) || file_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'
+ # => #<Dry::Types::Result::Failure input=:internal_resource error=...
+ # ```
+ if file_model_class.respond_to?(:internal_resource)
+ file_model_class.internal_resource
+ else
+ file_model_class.to_s
+ end
end
def curation_concerns
@curation_concerns ||= defined?(::Hyrax) ? ::Hyrax.config.curation_concerns : []
end
attr_writer :curation_concerns
def curation_concern_internal_resources
- curation_concerns.map { |cc| cc.try(:internal_resource) || cc.to_s }.uniq
+ curation_concerns.map do |cc|
+ # 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'
+ # => #<Dry::Types::Result::Failure input=:internal_resource error=...
+ # ```
+ cc.respond_to?(:internal_resource) ? cc.internal_resource : cc.to_s
+ end.uniq
end
attr_writer :ingest_queue_name
##
# @return [String, Proc]