class RDF::AllegroGraph::Catalog

An AllegroGraph catalog containing several repositories.

Attributes

catalog[R]

Public Class Methods

new(url_or_hash, options={}) click to toggle source

Create a new Catalog object.

@param [String] url The Sesame URL of the AllegroGraph server.

# File lib/rdf/allegro_graph/catalog.rb, line 11
def initialize(url_or_hash, options={})
  url_or_hash = Parser::parse_uri(url_or_hash) if url_or_hash.is_a?(String)
  server = url_or_hash[:server].server
  id = url_or_hash[:id]

  @name = id
  @catalog = AllegroGraph::Catalog.new(server, id)
  @catalog.create_if_missing! if options[:create]
end

Public Instance Methods

[](id, options={})
Alias for: repository
delete!() click to toggle source

Delete this catalog if it exists.

@return [void]

# File lib/rdf/allegro_graph/catalog.rb, line 24
def delete!
  @catalog.delete!
end
each(&block)
Alias for: each_repository
each_repository(&block) click to toggle source

Iterate over all repositories.

@yield repository @yieldparam [Repository] repository @yieldreturn [void] @return [void]

# File lib/rdf/allegro_graph/catalog.rb, line 54
def each_repository(&block)
  repositories.values.each(&block)
end
Also aliased as: each
has_repository?(id) click to toggle source

Return true if the specified repository exists in the catalog.

@param [String] id The name of the repository. @return [Boolean]

# File lib/rdf/allegro_graph/catalog.rb, line 44
def has_repository?(id)
  repositories.has_key?(id)
end
repositories() click to toggle source

Return a hash table of all repositories in this catalog.

@return [Hash<String,Repository>]

# File lib/rdf/allegro_graph/catalog.rb, line 31
def repositories
  result = {}
  repositories = @catalog.server.request_json(:get, self.path(:repositories),
    :expected_status_code => 200).each do |repo|
    result[repo['id']] = Repository.new(:catalog => self, :id => repo['id'])
  end
  result
end
repository(id, options={}) click to toggle source

Look up a specific repository by name, and optionally create it.

@param [String] id The name of the repository. @param [Hash] options @option options [Boolean] :create

If true, and the repository does not exist, create it.

@return [Repository,nil]

The repository, if it exists or was created, or nil otherwise.
# File lib/rdf/allegro_graph/catalog.rb, line 67
def repository(id, options={})
  result = repositories[id]
  if result.nil? && options[:create]
    result = Repository.new({:catalog => self, :id => id}, :create => true)
  end
  result
end
Also aliased as: []

Protected Instance Methods

path(relativate_path=nil) click to toggle source

Generate a path to a resource on the catalog.

# File lib/rdf/allegro_graph/catalog.rb, line 79
def path(relativate_path=nil)
  if relativate_path
    "/catalogs/#{@name}/#{relativate_path}"
  else
    "/catalogs/#{@name}"
  end
end