Class: RDF::Sesame::Repository

Inherits:
RDF::Repository
  • Object
show all
Defined in:
lib/rdf/sesame/repository.rb

Overview

A repository on a Sesame 2.0-compatible HTTP server.

Instances of this class represent RDF repositories on Sesame-compatible servers.

This class implements the RDF::Repository interface; refer to the relevant RDF.rb API documentation for further usage instructions.

Examples:

Opening a Sesame repository (1)

url = "http://localhost:8080/openrdf-sesame/repositories/SYSTEM"
repository = RDF::Sesame::Repository.new(url)

Opening a Sesame repository (2)

server = RDF::Sesame::Server.new("http://localhost:8080/openrdf-sesame")
repository = RDF::Sesame::Repository.new(:server => server, :id => :SYSTEM)

Opening a Sesame repository (3)

server = RDF::Sesame::Server.new("http://localhost:8080/openrdf-sesame")
repository = server.repository(:SYSTEM)

See Also:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Object) initialize(url) {|repository| ... } - (Object) initialize(options = {}) {|repository| ... }

Initializes this Repository instance.

Overloads:

  • - (Object) initialize(url) {|repository| ... }

    Parameters:

    • (String, RDF::URI) url

    Yields:

    • (repository)

    Yield Parameters:

  • - (Object) initialize(options = {}) {|repository| ... }

    Parameters:

    • (Hash{Symbol => Object}) options

    Options Hash (options):

    • (Server) :server — default: nil
    • (String) :id — default: nil
    • (String) :title — default: nil

    Yields:

    • (repository)

    Yield Parameters:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rdf/sesame/repository.rb', line 58

def initialize(url_or_options, &block)
  case url_or_options
    when String
      initialize(RDF::URI.new(url_or_options), &block)

    when RDF::URI
      require 'pathname' unless defined?(Pathname)
      @uri     = url_or_options
      @server  = Server.new(RDF::URI.new({
        :scheme   => @uri.scheme,
        :userinfo => @uri.userinfo,
        :host     => @uri.host,
        :port     => @uri.port,
        :path     => Pathname.new(@uri.path).parent.parent.to_s, # + '../..'
      }))
      @options = {}

    when Hash
      raise ArgumentError, "missing options[:server]" unless url_or_options.has_key?(:server)
      raise ArgumentError, "missing options[:id]"     unless url_or_options.has_key?(:id)
      @options = url_or_options.dup
      @server  = @options.delete(:server)
      @id      = @options.delete(:id)
      @uri     = @options.delete(:uri) || server.url("repositories/#{@id}")
      @title   = @options.delete(:title)

    else
      raise ArgumentError, "expected String, RDF::URI or Hash, but got #{url_or_options.inspect}"
  end

  if block_given?
    case block.arity
      when 1 then block.call(self)
      else instance_eval(&block)
    end
  end
end

Instance Attribute Details

- (String) id (readonly)

Returns:

  • (String)


34
35
36
# File 'lib/rdf/sesame/repository.rb', line 34

def id
  @id
end

- (Server) server (readonly)

Returns:



40
41
42
# File 'lib/rdf/sesame/repository.rb', line 40

def server
  @server
end

- (String) title (readonly)

Returns:

  • (String)


37
38
39
# File 'lib/rdf/sesame/repository.rb', line 37

def title
  @title
end

- (RDF::URI) url(path = nil, query = {}) (readonly) Also known as: uri

Returns the URL for the given repository-relative path.

Parameters:

  • (String, #to_s) path (defaults to: nil)
  • (Hash, RDF::Statement) query (defaults to: {})

Returns:

  • (RDF::URI)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rdf/sesame/repository.rb', line 30

def url(path = nil, query = {})
  url = path ? RDF::URI.new("#{@uri}/#{path}") : @uri.dup # FIXME
  unless query.nil?
    case query
      when RDF::Statement
        writer = RDF::NTriples::Writer.new
        query  = {
          :subj    => writer.format_value(query.subject),
          :pred    => writer.format_value(query.predicate),
          :obj     => writer.format_value(query.object),
          :context => query.has_context? ? writer.format_value(query.context) : 'null',
        }
        url.query_values = query
      when Hash
        url.query_values = query unless query.empty?
    end
  end
  return url
end