Sha256: bd8d5fd6af0243eedad9f54cdaf064629f5bd58297cf7103f1cf70aaf2f20805

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module Vedeu

  # Provides all registered repositories.
  #
  module Repositories

    extend self

    # @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

require 'vedeu/repositories/store'
require 'vedeu/repositories/registerable'
require 'vedeu/repositories/collection'
require 'vedeu/repositories/model'
require 'vedeu/repositories/repository'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.4.57 lib/vedeu/repositories/all.rb
vedeu-0.4.56 lib/vedeu/repositories/all.rb
vedeu-0.4.55 lib/vedeu/repositories/all.rb