Sha256: 909ad6e9036a64f4adbafa37951b677e23192190b120b54bd9331006ede598d0

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Vedeu

  # Provides all registered repositories.
  #
  module Repositories

    extend self

    # Access all the repositories stored.
    #
    # @return [Array]
    def all
      storage.map(&:repository)
    end

    # Register a repository with the collection of Vedeu repositories.
    #
    # @param klass [Class]
    # @return [Set]
    def register(klass)
      storage.add(klass) if klass
    end

    # List all models stored in each registered repository.
    #
    # @return [Array]
    def registered
      all.map do |repository|
        registered = repository.send(:registered)

        Vedeu.log(type:    :store,
                  message: "Repository '#{repository.class.name}':" \
                           " #{registered.inspect}")

        registered
      end
    end

    # Remove all stored models from the repository.
    #
    # @return [Boolean]
    def reset!
      all.map { |repository| repository.send(:reset) }

      true
    end
    alias reset reset!

    private

    # Access to the storage for this repository.
    #
    # @return [Array]
    def storage
      @storage ||= Set.new
    end

  end # Repositories

end # Vedeu

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.8.12 lib/vedeu/repositories/repositories.rb
vedeu-0.8.10 lib/vedeu/repositories/repositories.rb
vedeu-0.8.9 lib/vedeu/repositories/repositories.rb
vedeu-0.8.8 lib/vedeu/repositories/repositories.rb
vedeu-0.8.7 lib/vedeu/repositories/repositories.rb