Module: RDF::Repository::Implementation
- Defined in:
- lib/rdf/repository.rb
Overview
A default Repository implementation supporting atomic writes and serializable transactions.
Constant Summary collapse
- DEFAULT_GRAPH =
false
- SerializedTransaction =
Deprecated.
moved to Transaction::SerializedTransaction
RDF::Transaction::SerializedTransaction
Class Method Summary collapse
Instance Method Summary collapse
- #apply_changeset(changeset) ⇒ Object
- #count ⇒ Object
- #each_graph(&block) ⇒ Object
- #each_statement(&block) ⇒ Object (also: #each)
- #graph?(*args) ⇒ Object (also: #has_graph?)
- #graph_names(options = nil, &block) ⇒ Object
- #isolation_level ⇒ Object
-
#snapshot ⇒ Dataset
A readable & queryable snapshot of the repository for isolated reads.
- #statement?(*args) ⇒ Object (also: #has_statement?)
- #supports?(feature) ⇒ Boolean
Class Method Details
.extend_object(obj) ⇒ Object
257 258 259 260 261 262 263 264 |
# File 'lib/rdf/repository.rb', line 257 def self.extend_object(obj) obj.instance_variable_set(:@data, obj..delete(:data) || Hash.new) obj.instance_variable_set(:@tx_class, obj..delete(:transaction_class) || RDF::Transaction::SerializedTransaction) super end |
Instance Method Details
#apply_changeset(changeset) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/rdf/repository.rb', line 374 def apply_changeset(changeset) data = @data changeset.deletes.each do |del| if del.constant? data = delete_from(data, del) else # we need this condition to handle wildcard statements query_pattern(del) { |stmt| data = delete_from(data, stmt) } end end changeset.inserts.each { |ins| data = insert_to(data, ins) } @data = data end |
#count ⇒ Object
286 287 288 289 290 291 292 293 294 |
# File 'lib/rdf/repository.rb', line 286 def count count = 0 @data.each do |_, ss| ss.each do |_, ps| ps.each { |_, os| count += os.size } end end count end |
#each_graph(&block) ⇒ Object
326 327 328 329 330 331 332 333 |
# File 'lib/rdf/repository.rb', line 326 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
356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/rdf/repository.rb', line 356 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, .merge(graph_name: g.equal?(DEFAULT_GRAPH) ? nil : g)) end end end end end enum_statement end |
#graph? ⇒ Boolean #graph?(name) ⇒ Boolean Also known as: has_graph?
307 308 309 310 311 312 313 |
# File 'lib/rdf/repository.rb', line 307 def graph?(*args) case args.length when 0 then false when 1 then @data.key?(args.first) else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)") end end |
#graph_names(options = nil, &block) ⇒ Object
319 320 321 |
# File 'lib/rdf/repository.rb', line 319 def graph_names( = nil, &block) @data.keys.reject { |g| g == DEFAULT_GRAPH }.to_a end |
#isolation_level ⇒ Object
390 391 392 |
# File 'lib/rdf/repository.rb', line 390 def isolation_level :snapshot end |
#snapshot ⇒ Dataset
A readable & queryable snapshot of the repository for isolated reads.
401 402 403 |
# File 'lib/rdf/repository.rb', line 401 def snapshot self.class.new(data: @data).freeze end |
#statement? ⇒ Boolean #statement?(statement) ⇒ Object Also known as: has_statement?
344 345 346 347 348 349 350 |
# File 'lib/rdf/repository.rb', line 344 def statement?(*args) case args.length when 0 then false when 1 then args.first && statement_in?(@data, args.first) else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)") end end |
#supports?(feature) ⇒ Boolean
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/rdf/repository.rb', line 269 def supports?(feature) case feature.to_sym when :graph_name then @options[:with_graph_name] when :validity then @options.fetch(:with_validity, true) when :literal_equality then true when :atomic_write then true when :rdf_full then true when :quoted_triples then true when :base_direction then true when :snapshots then true else false end end |