Sha256: 6e9aa466d9649426662d96864a506afd7e122132e657be8de3e05a9f25943834

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

module ActiveTriples
  ##
  # Defines module methods for registering an RDF::Repository for
  # persistence of Resources.
  #
  # This allows any triplestore (or other storage platform) with an
  # RDF::Repository implementation to be used for persistence of
  # resources that will be shared between ActiveFedora::Base objects.
  #
  #    ActiveTriples::Repositories.add_repository :blah, RDF::Repository.new
  #
  # Multiple repositories can be registered to keep different kinds of
  # resources seperate. This is configurable on subclasses of Resource
  # at the class level.
  #
  # @see Configurable
  module Repositories

    def add_repository(name, repo)
      raise "Repositories must be an RDF::Repository" unless repo.kind_of? RDF::Repository
      repositories[name] = repo
    end
    module_function :add_repository

    def clear_repositories!
      @repositories = {}
    end
    module_function :clear_repositories!

    def repositories
      @repositories ||= {}
    end
    module_function :repositories

    ##
    # Check for the specified rdf_subject in the specified repository
    # defaulting to search all registered repositories.
    # @param [String] rdf_subject
    # @param [Symbol] repository name
    def has_subject?(rdf_subject,repo_name=nil)
      search_repositories = [repositories[repo_name]] if repo_name
      search_repositories ||= repositories.values
      found = false
      search_repositories.each do |repo|
        found = repo.has_subject? rdf_subject
        break if found
      end
      found
    end
    module_function :has_subject?

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active-triples-0.7.2 lib/active_triples/repositories.rb
active-triples-0.7.1 lib/active_triples/repositories.rb
active-triples-0.7.0 lib/active_triples/repositories.rb
active-triples-0.6.1 lib/active_triples/repositories.rb
active-triples-0.6.0 lib/active_triples/repositories.rb