diff --git a/lib/rdf/transaction.rb b/lib/rdf/transaction.rb index 14b1d5b9..fad45895 100644 --- a/lib/rdf/transaction.rb +++ b/lib/rdf/transaction.rb @@ -74,7 +74,7 @@ class Transaction ## # @see RDF::Enumerable#each def each(*args, &block) - @snapshot.each(*args, &block) + read_target.each(*args, &block) end ## @@ -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. # @@ -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 @@ -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 diff --git a/spec/model_graph_spec.rb b/spec/model_graph_spec.rb index 64c4b3cc..57194877 100644 --- a/spec/model_graph_spec.rb +++ b/spec/model_graph_spec.rb @@ -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