Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/rdf/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Transaction
##
# @see RDF::Enumerable#each
def each(*args, &block)
@snapshot.each(*args, &block)
read_target.each(*args, &block)
end

##
Expand Down Expand Up @@ -203,6 +203,12 @@ def readable?
true
end

##
# @see RDF::Enumerable#has_statement?
def has_statement?(statement)
read_target.has_statement?(statement)
end

##
# Returns a developer-friendly representation of this transaction.
#
Expand Down Expand Up @@ -271,11 +277,11 @@ def delete_statement(statement)
end

def query_pattern(*args, &block)
@snapshot.send(:query_pattern, *args, &block)
read_target.send(:query_pattern, *args, &block)
end

def query_execute(*args, &block)
@snapshot.send(:query_execute, *args, &block)
read_target.send(:query_execute, *args, &block)
end

undef_method :load, :update, :clear
Expand All @@ -289,12 +295,18 @@ def query_execute(*args, &block)
# @param statement [RDF::Statement]
# @return [RDF::Statement]
def process_statement(statement)
if graph_name && statement.graph_name.nil?
if graph_name
statement = statement.dup
statement.graph_name = graph_name
end
statement
end

def read_target
return @snapshot if graph_name.nil?
return @snapshot.project_graph(nil) if graph_name == false
@snapshot.project_graph(graph_name)
end

public

Expand Down
9 changes: 9 additions & 0 deletions spec/model_graph_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@
context "when querying statements" do
require 'rdf/spec/queryable'
it_behaves_like 'an RDF::Queryable'

context 'with graph_name' do
require 'rdf/spec/queryable'
it_behaves_like 'an RDF::Queryable' do
let(:queryable) do
RDF::Graph.new(graph_name: RDF::URI('g'), data: RDF::Repository.new)
end
end
end
end

context "Examples" do
Expand Down