Skip to content

Commit

Permalink
favor #respond_to? over rescuing errors
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Kaufman <[email protected]>
  • Loading branch information
bkiahstroud and orangewolf committed Sep 26, 2024
1 parent 5ae4568 commit a5d3be4
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions lib/bulkrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,11 @@ def collection_model_internal_resource
# Hyrax::FileSet.try(:internal_resource) || 'hi'
# => #<Dry::Types::Result::Failure input=:internal_resource error=...
# ```
ir = begin
collection_model_class.internal_resource
rescue NoMethodError
nil
end

ir.presence || collection_model_class.to_s
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 @@ -132,13 +130,11 @@ def file_model_internal_resource
# Hyrax::FileSet.try(:internal_resource) || 'hi'
# => #<Dry::Types::Result::Failure input=:internal_resource error=...
# ```
ir = begin
file_model_class.internal_resource
rescue NoMethodError
nil
end

ir.presence || file_model_class.to_s
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 @@ -158,13 +154,7 @@ def curation_concern_internal_resources
# Hyrax::FileSet.try(:internal_resource) || 'hi'
# => #<Dry::Types::Result::Failure input=:internal_resource error=...
# ```
ir = begin
cc.internal_resource
rescue NoMethodError
nil
end

ir.presence || cc.to_s
cc.respond_to?(:internal_resource) ? cc.internal_resource : cc.to_s
end.uniq
end

Expand Down

0 comments on commit a5d3be4

Please sign in to comment.