Class: RDF::LDP::RDFSource
- Defined in:
- lib/rdf/ldp/rdf_source.rb
Overview
the contents of ‘#metagraph`’s are not the same as LDP-server-managed triples. ‘#metagraph` contains internal properties of the RDFSource which are necessary for the server’s management purposes, but MAY be absent from (or in conflict with) the representation of its state in ‘#graph`.
The base class for all directly usable LDP Resources that *are not* ‘NonRDFSources`. RDFSources are implemented as a resource with:
- a `#graph` representing the "entire persistent state"
- a `#metagraph` containing internal properties of the RDFSource
Repository implementations must be able to reconstruct both ‘#graph` and `#metagraph` accurately and separately (e.g., by saving them as distinct named graphs).
The implementations of ‘#create` and `#update` in `RDF::LDP::Resource` are overloaded to handle the edits to `#graph` within the same transaction as the base `#metagraph` updates. `#to_response` is overloaded to return an unnamed `RDF::Graph`, to be transformed into an HTTP Body by `Rack::LDP::ContentNegotiation`.
Direct Known Subclasses
Constant Summary
Constants inherited from Resource
RDF::LDP::Resource::CONTAINS_URI, RDF::LDP::Resource::INVALIDATED_AT_URI, RDF::LDP::Resource::MODIFIED_URI
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.to_uri ⇒ RDF::URI
Uri with lexical representation ‘www.w3.org/ns/ldp#RDFSource’.
Instance Method Summary collapse
-
#create(input, content_type) {|tx| ... } ⇒ RDF::LDP::Resource
Creates the RDFSource, populating its graph from the input given.
-
#destroy(&block) ⇒ Object
Clears the graph and marks as destroyed.
-
#graph ⇒ RDF::Graph
A graph representing the current persistent state of the resource.
-
#initialize(subject_uri, data = RDF::Repository.new) ⇒ RDFSource
constructor
A new instance of RDFSource.
-
#rdf_source? ⇒ Boolean
Whether this is an ldp:RDFSource.
-
#to_response ⇒ Object
Returns the graph representing this resource’s state, without the graph context.
-
#update(input, content_type) {|tx| ... } ⇒ RDF::LDP::Resource
Updates the resource.
Methods inherited from Resource
#allowed_methods, #container?, #containers, #destroyed?, #etag, #exists?, find, gen_id, interaction_model, #last_modified, #ldp_resource?, #match?, metagraph_name, #non_rdf_source?, #request, #to_uri
Constructor Details
Class Method Details
.to_uri ⇒ RDF::URI
Returns uri with lexical representation ‘www.w3.org/ns/ldp#RDFSource’.
37 38 39 |
# File 'lib/rdf/ldp/rdf_source.rb', line 37 def to_uri RDF::Vocab::LDP.RDFSource end |
Instance Method Details
#create(input, content_type) {|tx| ... } ⇒ RDF::LDP::Resource
Creates the RDFSource, populating its graph from the input given
100 101 102 103 104 105 |
# File 'lib/rdf/ldp/rdf_source.rb', line 100 def create(input, content_type, &block) super do |transaction| transaction.insert(parse_graph(input, content_type)) yield transaction if block_given? end end |
#destroy(&block) ⇒ Object
Clears the graph and marks as destroyed.
147 148 149 150 151 |
# File 'lib/rdf/ldp/rdf_source.rb', line 147 def destroy(&block) super do |tx| tx.delete(RDF::Statement(nil, nil, nil, graph_name: subject_uri)) end end |
#graph ⇒ RDF::Graph
Returns a graph representing the current persistent state of the resource.
54 55 56 |
# File 'lib/rdf/ldp/rdf_source.rb', line 54 def graph @graph ||= RDF::Graph.new(graph_name: @subject_uri, data: @data) end |
#rdf_source? ⇒ Boolean
Returns whether this is an ldp:RDFSource.
155 156 157 |
# File 'lib/rdf/ldp/rdf_source.rb', line 155 def rdf_source? true end |
#to_response ⇒ Object
Returns the graph representing this resource’s state, without the graph context.
162 163 164 |
# File 'lib/rdf/ldp/rdf_source.rb', line 162 def to_response RDF::Graph.new << graph end |
#update(input, content_type) {|tx| ... } ⇒ RDF::LDP::Resource
Updates the resource. Replaces the contents of ‘graph` with the parsed input.
134 135 136 137 138 139 140 141 |
# File 'lib/rdf/ldp/rdf_source.rb', line 134 def update(input, content_type, &block) 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 end |