lib/rdf/kv.rb in rdf-kv-0.1.1 vs lib/rdf/kv.rb in rdf-kv-0.1.3
- old
+ new
@@ -50,18 +50,21 @@
@prefixes[prefix.to_sym] = RDF::Vocabulary.new uri
end
},
}.freeze
+ def random_uuid_ncname
+ UUID::NCName.to_ncname_64 UUIDTools::UUID.random_create.to_s, version: 1
+ end
+
# macros are initially represented as a pair: the macro value and a
# flag denoting whether or not the macro itself contains macros and to
# try to dereference it.
GENERATED = {
NEW_UUID: [[-> { UUIDTools::UUID.random_create.to_s }, false]],
NEW_UUID_URN: [[-> { UUIDTools::UUID.random_create.to_uri }, false]],
- NEW_BNODE: [[-> { "_:#{UUID::NCName.to_ncname_64(
- UUIDTools::UUID.random_create.to_s, version: 1) }" }, false]],
+ NEW_BNODE: [[-> { "_:#{random_uuid_ncname}" }, false]],
}.freeze
# just the classics
DEFAULT_NS = {
rdf: RDF::RDFV,
@@ -387,22 +390,29 @@
# these terms have already been resolved/coerced
p = contents[:term1]
o = contents[:term2] || subject
else
s, p = (contents[:term2] ? contents.values_at(:term1, :term2) :
- [subject, contents[:term1]]).map { |t| resolve_term t }
+ [subject, contents[:term1]]).map do |t|
+ t = resolve_term t
+ callback ? callback.call(t) : t
+ end
end
# the operation depends on whether the `-` modifier is present
op = contents[:modifier][?-] ? :delete : :insert
# if we're deleting triples and the values contain an empty
# string then we're deleting a wildcard, same if we `=` overwrite
if !reverse and op == :delete && values.include?('') ||
contents[:modifier][?=]
+
+ # create a random variable name so we don't pass in a nil
+ var = RDF::Query::Variable.new random_uuid_ncname
+
# i can't remember why we don't do this in reverse, probably
# because it is too easy to shoot yourself in the foot
- patch.delete RDF::Statement(s, p, nil, graph_name: g)
+ patch.delete RDF::Statement(s, p, var, graph_name: g)
# nuke these since it will be pointless to evaluate further
values.clear if op == :delete
end