lib/ld/patch/algebra/delete.rb
##
# Executes this upate on the given `writable` graph or repository.
#
# @param  [RDF::Queryable] queryable
#   the graph or repository to write
# @param  [Hash{Symbol => Object}] options
#   any additional options
# @option options [Boolean] :existing
#   Specifies that triples must already exist in the target graph
# @return [RDF::Query::Solutions] A single solution including passed bindings with `var` bound to the solution.
# @raise [Error]
#   If `existing` is specified, and any triple is not found in the traget graph, or if unbound variables are used.
# @see    http://www.w3.org/TR/sparql11-update/
Executes this upate on the given `writable` graph or repository.
Executes this upate on the given ` writable ` graph or repository .
def execute(queryable, options = {})
      debug(options) {"Delete"}
      bindings = options.fetch(:bindings)
      solution = bindings.first
      triples = operand(0).dup.replace_vars! do |var|
        case var
        when RDF::Query::Pattern
          s = var.bind(solution)
          raise LD::Patch::Error.new("Operand uses unbound pattern #{var.inspect}", code: 400) if s.variable?
          s
        when RDF::Query::Variable
          raise LD::Patch::Error.new("Operand uses unbound variable #{var.inspect}", code: 400) unless solution.bound?(var)
          solution[var]
        end
      end
      if @options[:existing]
        triples.each do |triple|
          raise LD::Patch::Error, "Target graph does not contain triple #{triple.to_ntriples}" unless queryable.has_statement?(triple)
        end
      end
      queryable.delete(*triples)
      bindings
    end
def execute ( queryable , options = { } ) debug ( options ) { "Delete" } bindings = options . fetch ( :bindings ) solution = bindings . first triples = operand ( 0 ) . dup . replace_vars! do | var | case var when RDF :: Query :: Pattern s = var . bind ( solution ) raise LD :: Patch :: Error . new ( "Operand uses unbound pattern #{var.inspect}" , code : 400 ) if s . variable? s when RDF :: Query :: Variable raise LD :: Patch :: Error . new ( "Operand uses unbound variable #{var.inspect}" , code : 400 ) unless solution . bound? ( var ) solution [ var ] end end if @options [ :existing ] triples . each do | triple | raise LD :: Patch :: Error , "Target graph does not contain triple #{triple.to_ntriples}" unless queryable . has_statement? ( triple ) end end queryable . delete ( * triples ) bindings end
Executes this upate on the given `writable` graph or repository.
Executes this upate on the given ` writable ` graph or repository .
# Bind variables to triples # If `:new` is specified, verify that no triple in triples exists in queryable
A single solution including passed bindings with `var` bound to the solution.
A single solution including passed bindings with ` var ` bound to the solution .
RDF::Query::Solutions
[Error] If `existing` is specified, and any triple is not found in the traget graph, or if unbound variables are used.
[ Error ] If ` existing ` is specified and any triple is not found in the traget graph or if unbound variables are used .
queryable
<not_specific>
options
:existing Specifies that triples must already exist in the target graph
: existing Specifies that triples must already exist in the target graph
<not_specific>
options any additional options
options any additional options
see
None