class RDF::RedStore::Repository
An RDF::Repository backend for RedStore
.
Public Class Methods
new(options_or_uri = {})
click to toggle source
Create a new RDF::RedStore::Repository
.
@param [String] uri @param [Hash] opts @return [RDF::RedStore::Repository] @example
RDF::RedStore::Repository.new('http://localhost:8080/')
Calls superclass method
# File lib/rdf/redstore/repository.rb, line 25 def initialize(options_or_uri = {}) case options_or_uri when Hash @settings = options_or_uri.dup @uri = @settings[:uri].to_s else @settings = {} @uri = options_or_uri.to_s end super(uri_for(:query), @settings) end
Public Instance Methods
clear_statements()
click to toggle source
@private
# File lib/rdf/redstore/repository.rb, line 76 def clear_statements uri = uri_for(:data) Net::HTTP.start(uri.host, uri.port) do |http| http.delete(uri.path).code == '200' end end
count()
click to toggle source
@private
# File lib/rdf/redstore/repository.rb, line 38 def count uri = uri_for(:description) description = RDF::Graph.load(uri, :format => :ntriples) total = description.first_value(:predicate => SD.totalTriples) if total.nil? or total.to_i < 0 nil else total.to_i end end
delete_statement(statement, opts = {})
click to toggle source
@private
# File lib/rdf/redstore/repository.rb, line 62 def delete_statement(statement, opts = {}) if statement.invalid? delete_statements(query(statement), opts) else delete_statements([statement], opts) end end
delete_statements(statements, opts = {})
click to toggle source
@private
# File lib/rdf/redstore/repository.rb, line 71 def delete_statements(statements, opts = {}) post_statements(:delete, statements, opts) end
insert_statement(statement, opts = {})
click to toggle source
@private
# File lib/rdf/redstore/repository.rb, line 52 def insert_statement(statement, opts = {}) insert_statements([statement], opts) end
insert_statements(statements, opts = {})
click to toggle source
@private
# File lib/rdf/redstore/repository.rb, line 57 def insert_statements(statements, opts = {}) post_statements(:insert, statements, opts) end
post_statements(action, statements, opts = {})
click to toggle source
@private
# File lib/rdf/redstore/repository.rb, line 93 def post_statements(action, statements, opts = {}) graph = RDF::Graph.new graph.insert_statements(statements) content = RDF::Writer.for(:ntriples).dump(graph) uri = uri_for(action) req = Net::HTTP::Post.new(uri.path) req.form_data = { 'content' => content, 'content-type' => 'ntriples', 'graph' => opts[:context].to_s } Net::HTTP.start(uri.host, uri.port) do |http| response = http.request(req) response.code == '200' end end
uri_for(action)
click to toggle source
@private
# File lib/rdf/redstore/repository.rb, line 88 def uri_for(action) RDF::URI.parse(@uri+action.to_s) end
writable?()
click to toggle source
# File lib/rdf/redstore/repository.rb, line 83 def writable? true end