Class: RDF::AllegroGraph::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/allegro_graph/server.rb

Overview

An AllegroGraph server containing several repositories. We attempt to mimic the public API of RDF::Sesame::Server for the sake of convenience, though we do not implement several internal methods, and we generally attempt to raise errors when we can't connect to the server, unlike RDF::Sesame::Server, which just returns default values.

See Also:

  • Sesame::Server

Instance Method Summary collapse

Constructor Details

#initialize(url = "http://localhost:10035") ⇒ Server

Create a new Server object.

Parameters:

  • url (String) (defaults to: "http://localhost:10035")

    The Sesame URL of the AllegroGraph server.


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rdf/allegro_graph/server.rb', line 15

def initialize(url="http://localhost:10035")
  parsed = URI.parse(url)
  options = {
    :host => parsed.host, :post => parsed.port,
    :username => parsed.user, :password => parsed.password
  }
  @server = AllegroGraph::Server.new(options)
  
  unless parsed.path.nil? || parsed.path.empty? || parsed.path == "/"
    err = "AllegroGraph URLs with paths not supported: #{url}"
    raise ArgumentError.new(err)
  end
end

Instance Method Details

#each_repository {|repository| ... } Also known as: each

This method returns an undefined value.

Iterate over all repositories.

Yields:

  • repository

Yield Parameters:

Yield Returns:

  • (void)

64
65
66
# File 'lib/rdf/allegro_graph/server.rb', line 64

def each_repository(&block)
  repositories.values.each(&block)
end

#has_repository?(id) ⇒ Boolean

Return true if the specified repository exists on the server.

Parameters:

  • id (String)

    The name of the repository.

Returns:

  • (Boolean)

54
55
56
# File 'lib/rdf/allegro_graph/server.rb', line 54

def has_repository?(id)
  repositories.has_key?(id)
end

#protocolInteger Also known as: protocol_version

Get the protocol version supported by this server.

Returns:

  • (Integer)

32
33
34
35
# File 'lib/rdf/allegro_graph/server.rb', line 32

def protocol
  @server.request_http(:get, path(:protocol),
                       :expected_status_code => 200).to_i
end

#repositoriesHash<String,Repository>

Return a hash table of all repositories on this server.

Returns:


41
42
43
44
45
46
47
48
# File 'lib/rdf/allegro_graph/server.rb', line 41

def repositories
  result = {}
  @server.request_json(:get, path(:repositories),
                       :expected_status_code => 200).each do |repo|
    result[repo['id']] = Repository.new(:server => self, :id => repo['id'])
  end
  result
end

#repository(id, options = {}) ⇒ Repository? Also known as: []

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

Parameters:

  • id (String)

    The name of the repository.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :create (Boolean)

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

Returns:

  • (Repository, nil)

    The repository, if it exists or was created, or nil otherwise.


77
78
79
80
81
82
83
# File 'lib/rdf/allegro_graph/server.rb', line 77

def repository(id, options={})
  result = repositories[id]
  if result.nil? && options[:create]
    result = Repository.new(:server => self, :id => id, :create => true)
  end
  result
end