Class: RDF::Repository
- Inherits:
-
Object
- Object
- RDF::Repository
- Includes:
- Countable, Durable, Enumerable, Mutable, Queryable
- Defined in:
- lib/rdf/repository.rb
Overview
An RDF repository.
Defined Under Namespace
Modules: Implementation
Instance Attribute Summary (collapse)
-
- (Hash{Symbol => Object}) options
readonly
Returns the options passed to this repository when it was constructed.
-
- (String) title
readonly
Returns the title of this repository.
-
- (URI) uri
(also: #url)
readonly
Returns the URI of this repository.
Class Method Summary (collapse)
-
+ load(filenames, options = {}) {|repository| ... }
Loads one or more RDF files into a new transient in-memory repository.
Instance Method Summary (collapse)
-
- (RDF::Transaction) begin_transaction(context)
protected
Begins a new transaction.
-
- commit_transaction(tx)
protected
Commits the given transaction.
-
- (Repository) initialize(options = {}) {|repository| ... }
constructor
Initializes this repository instance.
-
- (String) inspect
Returns a developer-friendly representation of this object.
-
- inspect!
Outputs a developer-friendly representation of this object to
stderr. -
- rollback_transaction(tx)
protected
Rolls back the given transaction.
-
- transaction(context = nil) {|tx| ... }
(also: #transact)
Executes the given block in a transaction.
Methods included from Durable
Methods included from Util::Aliasing::LateBound
Methods included from Mutable
#<<, #clear, #delete, #delete_statement, #delete_statements, #immutable?, #insert, #load, #method_missing, #mutable?, #update
Methods included from Writable
#<<, #insert, #insert_graph, #insert_reader, #insert_statement, #insert_statements, #writable?
Methods included from Readable
Methods included from Queryable
#first, #first_literal, #first_object, #first_predicate, #first_subject, #first_value, #query, #query_execute, #query_pattern
Methods included from Enumerable
#contexts, #dump, #each_context, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_triple, #enum_context, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_triple, #has_context?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_triple?, #invalid?, #method_missing, #objects, #predicates, #quads, #statements, #subjects, #supports?, #to_a, #to_hash, #to_set, #triples, #valid?, #validate!
Methods included from Countable
Constructor Details
- (Repository) initialize(options = {}) {|repository| ... }
Initializes this repository instance.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rdf/repository.rb', line 101 def initialize( = {}, &block) @options = .dup @uri = @options.delete(:uri) @title = @options.delete(:title) # Provide a default in-memory implementation: send(:extend, Implementation) if self.class.equal?(RDF::Repository) if block_given? case block.arity when 1 then block.call(self) else instance_eval(&block) end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RDF::Mutable
Instance Attribute Details
- (Hash{Symbol => Object}) options (readonly)
Returns the options passed to this repository when it was constructed.
54 55 56 |
# File 'lib/rdf/repository.rb', line 54 def @options end |
- (String) title (readonly)
Returns the title of this repository.
67 68 69 |
# File 'lib/rdf/repository.rb', line 67 def title @title end |
Class Method Details
+ load(filenames, options = {}) {|repository| ... }
This method returns an undefined value.
Loads one or more RDF files into a new transient in-memory repository.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rdf/repository.rb', line 78 def self.load(filenames, = {}, &block) self.new() do |repository| [filenames].flatten.each do |filename| repository.load(filename, ) end if block_given? case block.arity when 1 then block.call(repository) else repository.instance_eval(&block) end end end end |
Instance Method Details
- (RDF::Transaction) begin_transaction(context) (protected)
Begins a new transaction.
Subclasses implementing transaction-capable storage adapters may wish to override this method in order to begin a transaction against the underlying storage.
178 179 180 |
# File 'lib/rdf/repository.rb', line 178 def begin_transaction(context) RDF::Transaction.new(:context => context) end |
- commit_transaction(tx) (protected)
This method returns an undefined value.
Commits the given transaction.
Subclasses implementing transaction-capable storage adapters may wish to override this method in order to commit the given transaction to the underlying storage.
206 207 208 |
# File 'lib/rdf/repository.rb', line 206 def commit_transaction(tx) tx.execute(self) end |
- (String) inspect
Returns a developer-friendly representation of this object.
121 122 123 |
# File 'lib/rdf/repository.rb', line 121 def inspect sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, uri.to_s) end |
- inspect!
This method returns an undefined value.
Outputs a developer-friendly representation of this object to
stderr.
130 131 132 133 |
# File 'lib/rdf/repository.rb', line 130 def inspect! each_statement { |statement| statement.inspect! } nil end |
- rollback_transaction(tx) (protected)
This method returns an undefined value.
Rolls back the given transaction.
Subclasses implementing transaction-capable storage adapters may wish to override this method in order to roll back the given transaction in the underlying storage.
192 193 194 |
# File 'lib/rdf/repository.rb', line 192 def rollback_transaction(tx) # nothing to do end |
- transaction(context = nil) {|tx| ... } Also known as: transact
This method returns an undefined value.
Executes the given block in a transaction.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/rdf/repository.rb', line 150 def transaction(context = nil, &block) tx = begin_transaction(context) begin case block.arity when 1 then block.call(tx) else tx.instance_eval(&block) end rescue => error rollback_transaction(tx) raise error end commit_transaction(tx) self end |