lib/rdf/ldp/container.rb in rdf-ldp-0.2.0 vs lib/rdf/ldp/container.rb in rdf-ldp-0.3.0

- old
+ new

@@ -1,6 +1,20 @@ module RDF::LDP + ## + # An LDP Basic Container. This also serves as a base class for other + # container types. Containers are implemented as `RDF::LDP::RDFSources` with + # the ability to contain other resources. + # + # Containers respond to `#post`, allowing new resources to be added to them. + # On the public interface (not running through HTTP/`#request`), this is + # supported by `#add` and `#remove`. + # + # Containers will throw errors when attempting to edit them in conflict with + # LDP's restrictions on changing containment triples. + # + # @see http://www.w3.org/TR/ldp/#dfn-linked-data-platform-container definition + # of LDP Container class Container < RDFSource ## # @return [RDF::URI] uri with lexical representation # 'http://www.w3.org/ns/ldp#Container' def self.to_uri @@ -97,9 +111,25 @@ def make_containment_triple(resource) RDF::Statement(subject_uri, RDF::Vocab::LDP.contains, resource) end private + + def patch(status, headers, env) + check_precondition!(env) + method = patch_types[env['CONTENT_TYPE']] + + raise UnsupportedMediaType unless method + + temp_graph = RDF::Graph.new << graph.statements + send(method, env['rack.input'], temp_graph) + + validate_triples!(temp_graph) + graph.clear! + graph << temp_graph.statements + + [200, update_headers(headers), self] + end ## # Handles a POST request. Parses a graph in the body of `env` and treats all # statements in that graph (irrespective of any graph names) as constituting # the initial state of the created source.