<commit_before>require 'active_admin/resource'

module ActiveAdmin
  class Resource
    class BelongsTo

      class TargetNotFound < StandardError; end

      # The resource which initiated this relationship
      attr_reader :owner

      def initialize(owner, target_name, options = {})
        @owner, @target_name, @options = owner, target_name, options
      end

      # Returns the target resource class or raises an exception if it doesn't exist
      def target
        key = @target_name.to_s.camelize
        namespace.resources[key] or raise TargetNotFound, "Could not find #{key} in" +
          " #{namespace.name} with #{namespace.resources.map(&:resource_name)}"
      end

      def namespace
        @owner.namespace
      end

      def optional?
        @options[:optional]
      end

      def required?
        !optional?
      end
    end
  end
end
<commit_msg>refactor TargetNotFound Error<commit_after>require 'active_admin/resource'

module ActiveAdmin
  class Resource
    class BelongsTo

      class TargetNotFound < StandardError
        def initialize(key, namespace)
          super "Could not find #{key} in #{namespace.name} " +
                "with #{namespace.resources.map(&:resource_name)}"
        end
      end

      # The resource which initiated this relationship
      attr_reader :owner

      def initialize(owner, target_name, options = {})
        @owner, @target_name, @options = owner, target_name, options
      end

      # Returns the target resource class or raises an exception if it doesn't exist
      def target
        key = @target_name.to_s.camelize
        namespace.resources[key] or raise TargetNotFound.new key, namespace
      end

      def namespace
        @owner.namespace
      end

      def optional?
        @options[:optional]
      end

      def required?
        !optional?
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07173219978746015, 'fraction_numerical': 0.0, 'mean_word_length': 2.368515205724508, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2543233', 'n_tokens_mistral': 500, 'n_tokens_neox': 484, 'n_words': 161}