From 45b408524eda6a38f6c2734a63b5f1ca3eee4b17 Mon Sep 17 00:00:00 2001 From: vangberg Date: Tue, 2 Jun 2026 14:18:31 +0200 Subject: [PATCH] Service rename to work with Zeitwerk https://github.com/seq-code/registry/issues/268 --- app/services/name/type_resolver.rb | 29 --------------------------- app/services/type_resolver_service.rb | 25 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 29 deletions(-) delete mode 100644 app/services/name/type_resolver.rb create mode 100644 app/services/type_resolver_service.rb diff --git a/app/services/name/type_resolver.rb b/app/services/name/type_resolver.rb deleted file mode 100644 index 6dbb9172..00000000 --- a/app/services/name/type_resolver.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Services - module Name - # Service object to resolve the nomenclatural type for a name. - # This encapsulates the logic for determining the type_of_type value - # and handling edge cases. - class TypeResolver - # Resolves the nomenclatural type class for a given object. - # @param object [Object, nil] The object to resolve (e.g., a Name, Genome, or Strain). - # @return [String] The resolved type_of_type value, or 'unknown' if unresolved. - def self.resolve(object) - return 'unknown' if object.nil? - return object.type_of_type if object.respond_to?(:type_of_type) - 'unknown' - end - - # Resolves the nomenclatural type class for a given object, with additional context. - # @param object [Object, nil] The object to resolve. - # @param context [Hash] Additional context (e.g., { fallback: 'Name' }). - # @return [String] The resolved type_of_type value. - def self.resolve_with_context(object, context = {}) - resolved = resolve(object) - return resolved unless resolved == 'unknown' && context[:fallback].present? - context[:fallback] - end - end - end -end diff --git a/app/services/type_resolver_service.rb b/app/services/type_resolver_service.rb new file mode 100644 index 00000000..bd26d334 --- /dev/null +++ b/app/services/type_resolver_service.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# Service object to resolve the nomenclatural type for a name. +# This encapsulates the logic for determining the type_of_type value +# and handling edge cases. +class TypeResolverService + # Resolves the nomenclatural type class for a given object. + # @param object [Object, nil] The object to resolve (e.g., a Name, Genome, or Strain). + # @return [String] The resolved type_of_type value, or 'unknown' if unresolved. + def self.resolve(object) + return 'unknown' if object.nil? + return object.type_of_type if object.respond_to?(:type_of_type) + 'unknown' + end + + # Resolves the nomenclatural type class for a given object, with additional context. + # @param object [Object, nil] The object to resolve. + # @param context [Hash] Additional context (e.g., { fallback: 'Name' }). + # @return [String] The resolved type_of_type value. + def self.resolve_with_context(object, context = {}) + resolved = resolve(object) + return resolved unless resolved == 'unknown' && context[:fallback].present? + context[:fallback] + end +end