lib/rdf/ldp/rdf_source.rb in rdf-ldp-0.6.0 vs lib/rdf/ldp/rdf_source.rb in rdf-ldp-0.7.0
- old
+ new
@@ -96,12 +96,11 @@
# @raise [RDF::LDP::Conflict] if the RDFSource already exists
#
# @return [RDF::LDP::Resource] self
def create(input, content_type, &block)
super do |transaction|
- statements = parse_graph(input, content_type)
- transaction.insert(statements)
+ transaction.insert(parse_graph(input, content_type))
yield transaction if block_given?
end
end
##
@@ -135,11 +134,10 @@
super do |transaction|
transaction.delete(RDF::Statement(nil, nil, nil, graph_name: subject_uri))
transaction.insert parse_graph(input, content_type)
yield transaction if block_given?
end
- self
end
##
# Clears the graph and marks as destroyed.
#
@@ -191,17 +189,17 @@
{ 'text/ldpatch' => :ld_patch,
'application/sparql-update' => :sparql_update }
end
def ld_patch(input, graph, &block)
- LD::Patch.parse(input).execute(graph)
+ LD::Patch.parse(input.read).execute(graph)
rescue LD::Patch::Error => e
raise BadRequest, e.message
end
def sparql_update(input, graph)
- SPARQL.execute(input, graph, update: true)
+ SPARQL.execute(input.read, graph, update: true)
rescue SPARQL::MalformedQuery => e
raise BadRequest, e.message
end
##
@@ -243,14 +241,13 @@
# for documentation on input streams in the Rack SPEC
def parse_graph(input, content_type)
reader = RDF::Reader.for(content_type: content_type.to_s)
raise(RDF::LDP::UnsupportedMediaType, content_type) if reader.nil?
- input = input.read if input.respond_to? :read
-
begin
+ input.rewind
RDF::Graph.new(graph_name: subject_uri, data: RDF::Repository.new) <<
- reader.new(input, base_uri: subject_uri, validate: true)
+ reader.new(input.read, base_uri: subject_uri, validate: true)
rescue RDF::ReaderError => e
raise RDF::LDP::BadRequest, e.message
end
end
end