Sha256: ea8091dcaf9406672401c553798e16a3caf047e3b27ce7c3b6521a9cffa4418b

Contents?: true

Size: 1.51 KB

Versions: 16

Compression:

Stored size: 1.51 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

    # Access all the repositories stored.
    #
    # @return [Array]
    def repositories
      self
    end

    # Remove all stored models from the repository.
    #
    # @return [Boolean]
    def reset!
      storage.map do |repository|
        Vedeu.log(type:    :red,
                  message: "Resetting: #{repository.name}")
        repository.reset!
      end

      true
    end
    alias reset reset!

    private

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

  end # Repositories

  # @!method repositories
  #   @see Vedeu::Repositories
  def_delegators Vedeu::Repositories,
                 :repositories

end # Vedeu

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/repositories/repositories.rb
vedeu-0.8.31 lib/vedeu/repositories/repositories.rb
vedeu-0.8.30 lib/vedeu/repositories/repositories.rb
vedeu-0.8.29 lib/vedeu/repositories/repositories.rb
vedeu-0.8.28 lib/vedeu/repositories/repositories.rb
vedeu-0.8.27 lib/vedeu/repositories/repositories.rb
vedeu-0.8.26 lib/vedeu/repositories/repositories.rb
vedeu-0.8.25 lib/vedeu/repositories/repositories.rb
vedeu-0.8.24 lib/vedeu/repositories/repositories.rb
vedeu-0.8.23 lib/vedeu/repositories/repositories.rb
vedeu-0.8.22 lib/vedeu/repositories/repositories.rb
vedeu-0.8.21 lib/vedeu/repositories/repositories.rb
vedeu-0.8.20 lib/vedeu/repositories/repositories.rb
vedeu-0.8.19 lib/vedeu/repositories/repositories.rb
vedeu-0.8.18 lib/vedeu/repositories/repositories.rb
vedeu-0.8.17 lib/vedeu/repositories/repositories.rb