Sha256: 739e0cd4b956446eadb9195fbca52c3de6968b619ac422053fd0ca359efedd97

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

module Vedeu

  # Provides all registered repositories.
  #
  module Repositories

    extend self

    # Register a repository with the collection of Vedeu repositories.
    #
    # @param klass [Class]
    # @return [Set]
    def register(klass)
      storage.add(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:    :debug,
                  message: "Repository '#{repository.class.name}':" \
                           " #{registered.inspect}")

        registered
      end
    end

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

      true
    end

    private

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

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

  end # Repositories

end # Vedeu

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vedeu-0.4.62 lib/vedeu/repositories.rb
vedeu-0.4.61 lib/vedeu/repositories.rb
vedeu-0.4.60 lib/vedeu/repositories.rb
vedeu-0.4.59 lib/vedeu/repositories.rb