Module: RDF::Repository::Implementation
- Defined in:
- lib/rdf/repository.rb
Overview
A default Repository implementation supporting atomic writes and serializable transactions.
Defined Under Namespace
Classes: SerializedTransaction
Constant Summary
collapse
- DEFAULT_GRAPH =
false
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.extend_object(obj) ⇒ Object
248
249
250
251
252
253
254
255
|
# File 'lib/rdf/repository.rb', line 248
def self.extend_object(obj)
obj.instance_variable_set(:@data, obj.options.delete(:data) ||
Hamster::Hash.new)
obj.instance_variable_set(:@tx_class,
obj.options.delete(:transaction_class) ||
SerializedTransaction)
super
end
|
Instance Method Details
#apply_changeset(changeset) ⇒ Object
345
346
347
348
349
350
|
# File 'lib/rdf/repository.rb', line 345
def apply_changeset(changeset)
data = @data
changeset.deletes.each { |del| data = delete_from(data, del) }
changeset.inserts.each { |ins| data = insert_to(data, ins) }
@data = data
end
|
#count ⇒ Object
274
275
276
277
278
279
280
281
282
|
# File 'lib/rdf/repository.rb', line 274
def count
count = 0
@data.each do |_, ss|
ss.each do |_, ps|
ps.each { |_, os| count += os.size }
end
end
count
end
|
#durable? ⇒ Boolean
287
288
289
|
# File 'lib/rdf/repository.rb', line 287
def durable?
false
end
|
#each_graph(&block) ⇒ Object
308
309
310
311
312
313
314
315
|
# File 'lib/rdf/repository.rb', line 308
def each_graph(&block)
if block_given?
@data.each_key do |gn|
yield RDF::Graph.new(graph_name: (gn == DEFAULT_GRAPH ? nil : gn), data: self)
end
end
enum_graph
end
|
#each_statement(&block) ⇒ Object
Also known as:
each
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
# File 'lib/rdf/repository.rb', line 327
def each_statement(&block)
if block_given?
@data.each do |g, ss|
ss.each do |s, ps|
ps.each do |p, os|
os.each do |o|
yield RDF::Statement.new(s, p, o, graph_name: g.equal?(DEFAULT_GRAPH) ? nil : g)
end
end
end
end
end
enum_statement
end
|
#graph_names(options = nil, &block) ⇒ Object
301
302
303
|
# File 'lib/rdf/repository.rb', line 301
def graph_names(options = nil, &block)
@data.keys.reject { |g| g == DEFAULT_GRAPH }.to_a
end
|
#has_graph?(graph) ⇒ Boolean
294
295
296
|
# File 'lib/rdf/repository.rb', line 294
def has_graph?(graph)
@data.has_key?(graph)
end
|
#has_statement?(statement) ⇒ Boolean
320
321
322
|
# File 'lib/rdf/repository.rb', line 320
def has_statement?(statement)
has_statement_in?(@data, statement)
end
|
#isolation_level ⇒ Object
354
355
356
|
# File 'lib/rdf/repository.rb', line 354
def isolation_level
:serializable
end
|
A readable & queryable snapshot of the repository for isolated reads.
365
366
367
|
# File 'lib/rdf/repository.rb', line 365
def snapshot
self.class.new(data: @data).freeze
end
|
#supports?(feature) ⇒ Boolean
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/rdf/repository.rb', line 260
def supports?(feature)
case feature.to_sym
when :graph_name then @options[:with_graph_name]
when :inference then false when :validity then @options.fetch(:with_validity, true)
when :atomic_write then true
when :snapshots then true
else false
end
end
|