Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid false positive from .try(:internal_resource) #980

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions lib/bulkrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,20 @@ 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'
# => #<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
Expand All @@ -108,7 +121,20 @@ def file_model_class
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
Expand All @@ -118,7 +144,18 @@ def curation_concerns
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
Expand Down
Loading