Class: RDF::Transaction
- Inherits:
-
Object
- Object
- RDF::Transaction
- Includes:
- Mutable
- Defined in:
- lib/rdf/transaction.rb
Overview
An RDF transaction.
Transactions consist of a sequence of RDF statements to delete from and a sequence of RDF statements to insert into a given named graph.
Instance Attribute Summary collapse
-
#deletes ⇒ RDF::Enumerable
readonly
RDF statements to delete when executed.
-
#graph ⇒ RDF::Resource
readonly
RDF graph to modify when executed.
-
#inserts ⇒ RDF::Enumerable
readonly
RDF statements to insert when executed.
-
#options ⇒ Hash{Symbol => Object}
readonly
Any additional options for this transaction.
Class Method Summary collapse
-
.execute(repository, options = {}) {|tx| ... } ⇒ void
Executes a transaction against the given RDF repository.
Instance Method Summary collapse
-
#execute(repository, options = {}) ⇒ void
Executes this transaction against the given RDF repository.
-
#initialize(options = {}) {|tx| ... } ⇒ Transaction
constructor
Initializes this transaction.
-
#inspect ⇒ String
Returns a developer-friendly representation of this transaction.
-
#inspect! ⇒ void
Outputs a developer-friendly representation of this transaction to ‘stderr`.
-
#readable? ⇒ Boolean
Returns ‘false` to indicate that this transaction is append-only.
Methods included from Mutable
#<<, #clear, #delete, #immutable?, #insert, #load, #mutable?, #update
Methods included from Util::Aliasing::LateBound
Methods included from Writable
Constructor Details
#initialize(options = {}) {|tx| ... } ⇒ Transaction
Initializes this transaction.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rdf/transaction.rb', line 65 def initialize( = {}, &block) @options = .dup @graph = @options.delete(:graph) || @options.delete(:context) @inserts = @options.delete(:insert) || RDF::Graph.new @deletes = @options.delete(:delete) || RDF::Graph.new @inserts.extend(RDF::Enumerable) unless @inserts.kind_of?(RDF::Enumerable) @deletes.extend(RDF::Enumerable) unless @deletes.kind_of?(RDF::Enumerable) if block_given? case block.arity when 1 then block.call(self) else instance_eval(&block) end end end |
Instance Attribute Details
#deletes ⇒ RDF::Enumerable (readonly)
RDF statements to delete when executed.
42 43 44 |
# File 'lib/rdf/transaction.rb', line 42 def deletes @deletes end |
#graph ⇒ RDF::Resource (readonly)
RDF graph to modify when executed.
36 37 38 |
# File 'lib/rdf/transaction.rb', line 36 def graph @graph end |
#inserts ⇒ RDF::Enumerable (readonly)
RDF statements to insert when executed.
48 49 50 |
# File 'lib/rdf/transaction.rb', line 48 def inserts @inserts end |
#options ⇒ Hash{Symbol => Object} (readonly)
Any additional options for this transaction.
54 55 56 |
# File 'lib/rdf/transaction.rb', line 54 def @options end |
Class Method Details
.execute(repository, options = {}) {|tx| ... } ⇒ void
This method returns an undefined value.
Executes a transaction against the given RDF repository.
28 29 30 |
# File 'lib/rdf/transaction.rb', line 28 def self.execute(repository, = {}, &block) self.new(&block).execute(repository, ) end |
Instance Method Details
#execute(repository, options = {}) ⇒ void
This method returns an undefined value.
Executes this transaction against the given RDF repository.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/rdf/transaction.rb', line 100 def execute(repository, = {}) before_execute(repository, ) if respond_to?(:before_execute) deletes.each_statement do |statement| statement = statement.dup statement.context = graph repository.delete(statement) end inserts.each_statement do |statement| statement = statement.dup statement.context = graph repository.insert(statement) end after_execute(repository, ) if respond_to?(:after_execute) self end |
#inspect ⇒ String
Returns a developer-friendly representation of this transaction.
123 124 125 126 |
# File 'lib/rdf/transaction.rb', line 123 def inspect sprintf("#<%s:%#0x(graph: %s, deletes: %d, inserts: %d)>", self.class.name, __id__, graph ? graph.to_s : 'nil', deletes.count, inserts.count) end |
#inspect! ⇒ void
This method returns an undefined value.
Outputs a developer-friendly representation of this transaction to ‘stderr`.
133 134 135 |
# File 'lib/rdf/transaction.rb', line 133 def inspect! warn(inspect) end |
#readable? ⇒ Boolean
90 91 92 |
# File 'lib/rdf/transaction.rb', line 90 def readable? false end |