Skip to content

Commit

Permalink
Handle Enumerable values on Repository#delete
Browse files Browse the repository at this point in the history
A test for `RDF::Enumerable` inputs was added by
ruby-rdf/rdf-spec#39. This adds conformance, and
allows `SPARQL::Client::Repository` to use the new
`Mutable#delete_insert` interface. It does not yet implement an
effecient SPARQL `#delete_insert`.

It may be possible to refactor `#delete_statements` in response to these
changes, to remove the code smells called out in the comment in that
method.
  • Loading branch information
Tom Johnson committed Nov 7, 2015
1 parent 311b7b6 commit d9a9ab3
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/sparql/client/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,27 @@ def clear_statements
# considered to be a pattern, and used to query
# self to find matching statements to delete.
#
# @param [Enumerable<RDF::Statement>] statements
# @raise [TypeError] if `self` is immutable
# @return [Mutable]
# @overload delete(*statements)
# @param [Array<RDF::Statement>] statements
# @raise [TypeError] if `self` is immutable
# @return [self]
#
# @overload delete(statements)
# @param [Enumerable<RDF::Statement>] statements
# @raise [TypeError] if `self` is immutable
# @return [self]
#
# @see RDF::Mutable#delete
def delete(*statements)
statements.map! do |value|
if value.respond_to?(:each_statement)
delete_statements(value)
nil
else
value
end
end
statements.compact!
delete_statements(statements) unless statements.empty?
return self
end
Expand Down Expand Up @@ -263,7 +280,6 @@ def query_pattern(pattern, options = {}, &block)
# @param [RDF::Enumerable] statements
# @return [void]
def delete_statements(statements)

constant = statements.all? do |value|
# needs to be flattened... urgh
!value.respond_to?(:each_statement) && begin
Expand Down

1 comment on commit d9a9ab3

@gkellogg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! We should definitely implement delete_insert using SPARQL Update here, but getting the specs to pass is the first step.

Please sign in to comment.