lib/rdf/ldp/rdf_source.rb in rdf-ldp-0.5.1 vs lib/rdf/ldp/rdf_source.rb in rdf-ldp-0.6.0

- old
+ new

@@ -51,11 +51,11 @@ ## # @return [RDF::Graph] a graph representing the current persistent state of # the resource. def graph - @graph ||= RDF::Graph.new(@subject_uri, data: @data) + @graph ||= RDF::Graph.new(graph_name: @subject_uri, data: @data) end ## # Creates the RDFSource, populating its graph from the input given # @@ -96,13 +96,12 @@ # @raise [RDF::LDP::Conflict] if the RDFSource already exists # # @return [RDF::LDP::Resource] self def create(input, content_type, &block) super do |transaction| - transaction.graph_name = subject_uri statements = parse_graph(input, content_type) - transaction << statements + transaction.insert(statements) yield transaction if block_given? end end ## @@ -132,26 +131,24 @@ # graph # # @return [RDF::LDP::Resource] self def update(input, content_type, &block) super do |transaction| - transaction.graph_name = subject_uri - transaction << parse_graph(input, content_type) + transaction.delete(RDF::Statement(nil, nil, nil, graph_name: subject_uri)) + transaction.insert parse_graph(input, content_type) yield transaction if block_given? - graph.clear end - self end ## # Clears the graph and marks as destroyed. # # @see RDF::LDP::Resource#destroy def destroy(&block) - super do |_| - graph.clear + super do |tx| + tx.delete(RDF::Statement(nil, nil, nil, graph_name: subject_uri)) end end ## # @return [Boolean] whether this is an ldp:RDFSource @@ -240,20 +237,20 @@ # # @return [RDF::Enumerable] the statements in the resulting graph # # @raise [RDF::LDP::UnsupportedMediaType] if no appropriate reader is found # - # @todo handle cases where no content type is given? Does RDF::Reader have - # tools to help us here? - # # @see http://www.rubydoc.info/github/rack/rack/file/SPEC#The_Input_Stream # 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 - RDF::Graph.new << reader.new(input, base_uri: subject_uri, validate: true) + RDF::Graph.new(graph_name: subject_uri, data: RDF::Repository.new) << + reader.new(input, base_uri: subject_uri, validate: true) rescue RDF::ReaderError => e raise RDF::LDP::BadRequest, e.message end end end