<commit_before>require "railjet/repository/active_record"
require "railjet/repository/cupido"

module Railjet
  module Repository
    extend  ::ActiveSupport::Concern

    attr_reader :registry
    delegate    :settings, to: :registry

    def initialize(registry, **kwargs)
      @registry = registry
      define_accessors(**kwargs)

      initialize_record_repository if defined?(record_repository_class)
      initialize_cupido_repository if defined?(cupido_repository_class)
    end

    private

    def define_accessors(**kwargs)
      kwargs.each do |name, val|
        repository_module.send(:define_method, name) { val }
        repository_module.send(:protected, name)
      end
    end

    def repository_module
      @repository_module ||= Module.new.tap { |m| self.class.include(m) }
    end

    def initialize_record_repository
      if respond_to?(:record, true)
        def self.record
          @record ||= record_repository_class.new(registry, super)
        end
      else
        def self.record
          @record ||= record_repository_class.new(registry)
        end
      end
    end

    def record_repository_class
      self.class::ActiveRecordRepository
    end

    def initialize_cupido_repository
      if respond_to?(:cupido, true)
        def self.cupido
          @cupido ||= cupido_repository_class.new(registry, super)
        end
      else
        def self.cupido
          @cupido ||= cupido_repository_class.new(registry)
        end
      end
    end

    def cupido_repository_class
      self.class::CupidoRepository
    end
  end
end<commit_msg>Simplifies repository in attempt to fix memory_leak<commit_after>require "railjet/repository/active_record"
require "railjet/repository/cupido"

module Railjet
  module Repository
    extend  ::ActiveSupport::Concern

    attr_reader :registry
    delegate    :settings, to: :registry

    def initialize(registry, sources = {})
      @registry = registry
      @sources  = sources
    end

    private

    def record
      if defined?(record_repository_class)
        @record ||= record_repository_class.new(
          registry, 
          @sources[:record]
        )
      end
    end

    def cupido
      if defined?(cupido_repository_class)
        @cupido ||= cupido_repository_class.new(
          registry,
          @sources[:cupido]
        )
      end
    end

    def record_repository_class
      self.class::ActiveRecordRepository
    end

    def cupido_repository_class
      self.class::CupidoRepository
    end
  end
end
{'fraction_non_alphanumeric': 0.07394226967180703, 'fraction_numerical': 0.0, 'mean_word_length': 2.6142857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3187861', 'n_tokens_mistral': 727, 'n_tokens_neox': 704, 'n_words': 158}