From ebc4af9b57ac708e70ae1ac3710d5dae4ed09340 Mon Sep 17 00:00:00 2001 From: Alexandra Dunn Date: Wed, 15 Sep 2021 16:07:02 -0700 Subject: [PATCH] sipity: add debug-level logging to #Entity 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. --- .rubocop_fixme.yml | 4 ++++ app/models/sipity.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/.rubocop_fixme.yml b/.rubocop_fixme.yml index cf7f0b930c..f8bad013e5 100644 --- a/.rubocop_fixme.yml +++ b/.rubocop_fixme.yml @@ -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' diff --git a/app/models/sipity.rb b/app/models/sipity.rb index 8d926403eb..410c18dbf3 100644 --- a/app/models/sipity.rb +++ b/app/models/sipity.rb @@ -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)