Class: RDF::LDP::RDFSource
- Defined in:
- lib/rdf/ldp/rdf_source.rb
Overview
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
Persistence schemes must be able to reconstruct both ‘#graph` and `#metagraph` accurately and separately (e.g. by saving them as distinct named graphs). Statements in `#metagraph` are considered canonical for the purposes of server-side operations; in the `RDF::LDP` core, this means they determine interaction model.
Note that the contents of ‘#metagraph`’s are not the same as LDP-server-managed triples. ‘#metagraph` contains statements internal properties of the RDFSource which are necessary for the server’s management purposes, but MAY be absent from the representation of its state in ‘#graph`.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#graph ⇒ Object
a graph representing the current persistent state of the resource.
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) {|the| ... } ⇒ RDF::LDP::Resource
Creates the RDFSource, populating its graph from the input given.
-
#destroy ⇒ Object
Clears the graph and marks as destroyed.
-
#etag ⇒ String
Returns an Etag.
-
#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) {|the| ... } ⇒ RDF::LDP::Resource
Updates the resource.
Methods inherited from Resource
#allowed_methods, #container?, #containers, #destroyed?, #exists?, find, gen_id, interaction_model, #ldp_resource?, #match?, #non_rdf_source?, #request, #to_uri
Constructor Details
Instance Attribute Details
#graph ⇒ Object
a graph representing the current persistent state of the resource.
29 30 31 |
# File 'lib/rdf/ldp/rdf_source.rb', line 29 def graph @graph end |
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) {|the| ... } ⇒ RDF::LDP::Resource
Creates the RDFSource, populating its graph from the input given
70 71 72 73 74 75 76 |
# File 'lib/rdf/ldp/rdf_source.rb', line 70 def create(input, content_type, &block) super statements = parse_graph(input, content_type) yield statements if block_given? graph << statements self end |
#destroy ⇒ Object
Clears the graph and marks as destroyed.
110 111 112 113 |
# File 'lib/rdf/ldp/rdf_source.rb', line 110 def destroy @graph.clear super end |
#etag ⇒ String
add an efficient hash function for RDF Graphs to RDF.rb and use that here?
the current implementation is a naive one that combines a couple of
Returns an Etag. This may be a strong or a weak ETag.
blunt heurisitics.
133 134 135 136 137 |
# File 'lib/rdf/ldp/rdf_source.rb', line 133 def etag subs = graph.subjects.map { |s| s.node? ? nil : s.to_s } .compact.sort.join() "\"#{Digest::SHA1.base64digest(subs)}#{graph.statements.count}\"" end |
#rdf_source? ⇒ Boolean
Returns whether this is an ldp:RDFSource.
148 149 150 |
# File 'lib/rdf/ldp/rdf_source.rb', line 148 def rdf_source? true end |
#to_response ⇒ Object
Returns the graph representing this resource’s state, without the graph context.
155 156 157 |
# File 'lib/rdf/ldp/rdf_source.rb', line 155 def to_response RDF::Graph.new << graph end |
#update(input, content_type) {|the| ... } ⇒ RDF::LDP::Resource
Updates the resource. Replaces the contents of ‘graph` with the parsed input.
97 98 99 100 101 102 103 104 |
# File 'lib/rdf/ldp/rdf_source.rb', line 97 def update(input, content_type, &block) return create(input, content_type) unless exists? statements = parse_graph(input, content_type) yield statements if block_given? graph.clear! graph << statements self end |