Class: RDF::Changeset
- Includes:
- Util::Coercions
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb
Overview
When applying a Changeset, deletes are resolved before inserts.
An RDF changeset that can be applied to an Mutable.
Changesets consist of a sequence of RDF statements to delete from and a sequence of RDF statements to insert into a target dataset.
Instance Attribute Summary collapse
-
#deletes ⇒ RDF::Enumerable
readonly
RDF statements to delete when applied.
-
#inserts ⇒ RDF::Enumerable
readonly
RDF statements to insert when applied.
-
#options ⇒ Hash{Symbol => Object}
readonly
Any additional options for this changeset.
Class Method Summary collapse
-
.apply(mutable, **options) {|changes| ... }
Applies a changeset to the given Mutable object.
Instance Method Summary collapse
-
#apply(mutable, **options)
Applies this changeset to the given mutable RDF::Enumerable.
-
#count ⇒ Integer
Returns the sum of both the
inserts
anddeletes
counts. -
#delete(*statements) ⇒ self
(also: #delete!, #>>)
Append statements to
deletes
. -
#empty? ⇒ Boolean
true
iff inserts and deletes are both empty. -
#initialize(insert: [], delete: []) {|changes| ... } ⇒ Changeset
constructor
Initializes this changeset.
-
#insert(*statements) ⇒ self
(also: #insert!, #<<)
Append statements to
inserts
. -
#inspect ⇒ String
Returns a developer-friendly representation of this changeset.
-
#inspect!
Outputs a developer-friendly representation of this changeset to
$stderr
. -
#mutable? ⇒ Boolean
Returns
false
as changesets are not Mutable. -
#readable? ⇒ Boolean
Returns
false
to indicate that this changeset is append-only. -
#writable? ⇒ Boolean
Returns
false
as changesets are not Writable.
Methods included from Util::Coercions
Constructor Details
#initialize(insert: [], delete: []) {|changes| ... } ⇒ Changeset
Initializes this changeset.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 74 def initialize(insert: [], delete: [], &block) @inserts = insert @deletes = delete @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 self.instance_eval(&block) end end end |
Instance Attribute Details
#deletes ⇒ RDF::Enumerable (readonly)
RDF statements to delete when applied.
53 54 55 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 53 def deletes @deletes end |
#inserts ⇒ RDF::Enumerable (readonly)
RDF statements to insert when applied.
59 60 61 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 59 def inserts @inserts end |
Class Method Details
.apply(mutable, **options) {|changes| ... }
This method returns an undefined value.
Applies a changeset to the given Mutable object.
45 46 47 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 45 def self.apply(mutable, **, &block) self.new(&block).apply(mutable, **) end |
Instance Method Details
#apply(mutable, **options)
This method returns an undefined value.
Applies this changeset to the given mutable RDF::Enumerable.
This operation executes as a single write transaction.
128 129 130 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 128 def apply(mutable, **) mutable.apply_changeset(self) end |
#count ⇒ Integer
Returns the sum of both the inserts
and deletes
counts.
160 161 162 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 160 def count inserts.count + deletes.count end |
#delete(*statements) ⇒ self Also known as: delete!, >>
Append statements to deletes
. Statements may contain
variables, although support will depend on the Mutable
target.
186 187 188 189 190 191 192 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 186 def delete(*statements) coerce_statements(statements) do |stmts| append_statements :deletes, stmts end self end |
#empty? ⇒ Boolean
Returns true
iff inserts and deletes are both empty.
134 135 136 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 134 def empty? deletes.empty? && inserts.empty? end |
#insert(*statements) ⇒ self Also known as: insert!, <<
Append statements to inserts
. Statements should be constant
as variable statements will at best be ignored or at worst raise
an error when applied.
170 171 172 173 174 175 176 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 170 def insert(*statements) coerce_statements(statements) do |stmts| append_statements :inserts, stmts end self end |
#inspect ⇒ String
Returns a developer-friendly representation of this changeset.
142 143 144 145 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 142 def inspect sprintf("#<%s:%#0x(deletes: %d, inserts: %d)>", self.class.name, self.__id__, self.deletes.count, self.inserts.count) end |
#inspect!
This method returns an undefined value.
Outputs a developer-friendly representation of this changeset to
$stderr
.
152 153 154 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 152 def inspect! $stderr.puts(self.inspect) end |
#mutable? ⇒ Boolean
Returns false
as changesets are not Mutable.
116 117 118 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 116 def mutable? false end |
#readable? ⇒ Boolean
98 99 100 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 98 def readable? false end |
#writable? ⇒ Boolean
Returns false
as changesets are not Writable.
107 108 109 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/changeset.rb', line 107 def writable? false end |