Class: RDF::LDP::RDFSource
- Defined in:
- lib/rdf/ldp/rdf_source.rb
Overview
the contents of ‘#metagraph`’s are not the same as
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`.
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`.
Direct Known Subclasses
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’.
38 39 40 |
# File 'lib/rdf/ldp/rdf_source.rb', line 38 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
99 100 101 102 103 104 105 106 |
# File 'lib/rdf/ldp/rdf_source.rb', line 99 def create(input, content_type, &block) super do |transaction| transaction.graph_name = subject_uri statements = parse_graph(input, content_type) transaction << statements yield transaction if block_given? end end |
#destroy(&block) ⇒ Object
Clears the graph and marks as destroyed.
150 151 152 153 154 |
# File 'lib/rdf/ldp/rdf_source.rb', line 150 def destroy(&block) super do |_| graph.clear end end |
#graph ⇒ RDF::Graph
Returns a graph representing the current persistent state of the resource.
55 56 57 |
# File 'lib/rdf/ldp/rdf_source.rb', line 55 def graph @graph ||= RDF::Graph.new(@subject_uri, data: @data) end |
#rdf_source? ⇒ Boolean
Returns whether this is an ldp:RDFSource.
158 159 160 |
# File 'lib/rdf/ldp/rdf_source.rb', line 158 def rdf_source? true end |
#to_response ⇒ Object
Returns the graph representing this resource’s state, without the graph context.
165 166 167 |
# File 'lib/rdf/ldp/rdf_source.rb', line 165 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.
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/rdf/ldp/rdf_source.rb', line 135 def update(input, content_type, &block) super do |transaction| transaction.graph_name = subject_uri transaction << parse_graph(input, content_type) yield transaction if block_given? graph.clear end self end |