# frozen_string_literal: true

module Upgrow
  # Base class for Repositories. It offers a basic API for the state all
  # Repositories should have, as well as the logic on how to materialize data
  # into Models.
  class BasicRepository
    class << self
      attr_writer :base

      # the base object to be used internally to retrieve the persisted data.
      # For example, a base class in which queries can be performed for a
      # relational database adapter. Defaults to `nil`.
      #
      # @return [Object] the Repository base.
      def base
        @base || default_base
      end

      private

      def default_base; end
    end

    attr_reader :base

    # Sets the Basic Repositorie's state.
    def initialize
      @base = self.class.base
    end
  end
end