Skip to content

Commit

Permalink
sipity: add debug-level logging to #Entity
Browse files Browse the repository at this point in the history
Because it's a recursive method, debugging entity creation can be difficult.
This helps trace the method flow when it's not clear how the input is being
transformed during the iterations.
  • Loading branch information
dunn authored and tamsin johnson committed Sep 16, 2021
1 parent 5e3ea97 commit ebc4af9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .rubocop_fixme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Security/MarshalLoad:
Exclude:
- 'app/models/concerns/hyrax/user.rb'

Metrics/AbcSize:
Exclude:
- 'app/models/sipity.rb'

Metrics/ClassLength:
Exclude:
- 'app/controllers/hyrax/dashboard/collections_controller.rb'
Expand Down
9 changes: 9 additions & 0 deletions app/models/sipity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,32 @@ def Agent(input, &block) # rubocop:disable Naming/MethodName
# @return [Sipity::Entity]
# rubocop:disable Naming/MethodName, Metrics/CyclomaticComplexity, Metrics/MethodLength
def Entity(input, &block)
Rails.logger.debug("Trying to make an Entity for #{input.inspect}")

result = case input
when Sipity::Entity
input
when URI::GID, GlobalID
Rails.logger.debug("Entity() got a GID, searching by proxy")
Entity.find_by(proxy_for_global_id: input.to_s)
when SolrDocument
Rails.logger.debug("Entity() got a SolrDocument, retrying on #{input.to_model}")
Entity(input.to_model)
when Draper::Decorator
Rails.logger.debug("Entity() got a Decorator, retrying on #{input.model}")
Entity(input.model)
when Sipity::Comment
Rails.logger.debug("Entity() got a Comment, retrying on #{input.entity}")
Entity(input.entity)
when Valkyrie::Resource
Rails.logger.debug("Entity() got a Resource, retrying on #{Hyrax::GlobalID(input)}")
Entity(Hyrax::GlobalID(input))
else
Rails.logger.debug("Entity() got something else, testing #to_global_id")
Entity(input.to_global_id) if input.respond_to?(:to_global_id)
end

Rails.logger.debug("Entity(): attempting conversion on #{result}")
handle_conversion(input, result, :to_sipity_entity, &block)
rescue URI::GID::MissingModelIdError
Entity(nil)
Expand Down

0 comments on commit ebc4af9

Please sign in to comment.