Class: RDF::Changeset

Inherits:
Object show all
Includes:
Mutable
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb

Overview

Note:

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.

Examples:

Applying a Changeset with block syntax

graph = RDF::Graph.new
graph << [RDF::URI('s_del'), RDF::URI('p_del'), RDF::URI('o_del')]

RDF::Changeset.apply(graph) do |c|
  c.insert [RDF::URI('s1'), RDF::URI('p1'), RDF::URI('o1')]
  c.insert [RDF::URI('s2'), RDF::URI('p2'), RDF::URI('o2')]
  c.delete [RDF::URI('s_del'), RDF::URI('p_del'), RDF::URI('o_del')]
end

Defining a changeset for later application to a Mutable

changes = RDF::Changeset.new do |c|
  c.insert [RDF::URI('s1'), RDF::URI('p1'), RDF::URI('o1')]
  c.insert [RDF::URI('s2'), RDF::URI('p2'), RDF::URI('o2')]
  c.delete [RDF::URI('s_del'), RDF::URI('p_del'), RDF::URI('o_del')]
end

graph = RDF::Graph.new
graph << [RDF::URI('s_del'), RDF::URI('p_del'), RDF::URI('o_del')]

changes.apply(graph) # or graph.apply_changeset(changes)

Since:

  • 2.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mutable

#<<, add_entailment, #apply_changeset, #clear, #delete, #delete_insert, #delete_statements, #entail, #entail!, #immutable?, #insert, #load, #method_missing, #mutable?, #respond_to_missing?, #snapshot, #update

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Writable

#<<, #insert, #insert_graph, #insert_reader, #insert_statements, #writable?

Constructor Details

#initialize(insert: [], delete: []) {|changes| ... } ⇒ Changeset

Initializes this changeset.

Parameters:

Yields:

  • (changes)

Yield Parameters:

Since:

  • 2.0.0



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 73

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Mutable

Instance Attribute Details

#deletesRDF::Enumerable (readonly)

RDF statements to delete when applied.

Returns:

Since:

  • 2.0.0



52
53
54
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 52

def deletes
  @deletes
end

#insertsRDF::Enumerable (readonly)

RDF statements to insert when applied.

Returns:

Since:

  • 2.0.0



58
59
60
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 58

def inserts
  @inserts
end

#optionsHash{Symbol => Object} (readonly)

Any additional options for this changeset.

Returns:

Since:

  • 2.0.0



64
65
66
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 64

def options
  @options
end

Class Method Details

.apply(mutable, **options) {|changes| ... }

This method returns an undefined value.

Applies a changeset to the given mutable RDF::Enumerable .

Parameters:

Yields:

  • (changes)

Yield Parameters:

Since:

  • 2.0.0



44
45
46
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 44

def self.apply(mutable, **options, &block)
  self.new(&block).apply(mutable, options)
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.

Parameters:

Since:

  • 2.0.0



109
110
111
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 109

def apply(mutable, **options)
  mutable.apply_changeset(self)
end

#delete_statement(statement) (protected)

This method returns an undefined value.

Appends an RDF statement to the sequence to delete when applied.

Parameters:

See Also:

Since:

  • 2.0.0



155
156
157
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 155

def delete_statement(statement)
  self.deletes << statement
end

#empty?Boolean

Returns true iff inserts and deletes are both empty

Returns:

  • (Boolean)

    true iff inserts and deletes are both empty

Since:

  • 2.0.0



115
116
117
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 115

def empty?
  deletes.empty? && inserts.empty?
end

#insert_statement(statement) (protected)

This method returns an undefined value.

Appends an RDF statement to the sequence to insert when applied.

Parameters:

See Also:

Since:

  • 2.0.0



145
146
147
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 145

def insert_statement(statement)
  self.inserts << statement
end

#inspectString

Returns a developer-friendly representation of this changeset.

Returns:

Since:

  • 2.0.0



123
124
125
126
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 123

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.

Since:

  • 2.0.0



133
134
135
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 133

def inspect!
  $stderr.puts(self.inspect)
end

#readable?Boolean

Returns false to indicate that this changeset is append-only.

Changesets do not support the RDF::Enumerable protocol directly. To enumerate the RDF statements to be inserted or deleted, use the #inserts and #deletes accessors.

Returns:

  • (Boolean)

See Also:

Since:

  • 2.0.0



97
98
99
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/changeset.rb', line 97

def readable?
  false
end