Module: Krikri::LDP::RdfSource
- Extended by:
- ActiveSupport::Concern
- Includes:
- Invalidatable, Resource
- Included in:
- OriginalRecordMetadata
- Defined in:
- lib/krikri/ldp/rdf_source.rb
Overview
Adds simple LDP persistence to ActiveTriples::Resource classes
Constant Summary collapse
- GENERATED_URI =
RDF::PROV.wasGeneratedBy
- REVISED_URI =
RDF::DPLA.wasRevisedBy
Constants included from Invalidatable
Invalidatable::INVALIDATED_BY_URI, Invalidatable::INVALIDATED_TIME_URI
Instance Method Summary collapse
-
#exists? ⇒ Boolean
(also: #exist?)
False if this resource does not ex.
-
#get(*args) ⇒ Object
GETs the LDP resource from #rdf_subject and resets this object’s RDF::Graph to match the one returned from the LDP server.
- #rdf_source ⇒ self
-
#save ⇒ Object
PUTs the LDP resource named in #rdf_subject, populating it’s content (graph) from the object’s RDF::Graph.
-
#save_and_reload(*args) ⇒ Object
Saves and forces reload.
-
#save_with_provenance(activity_uri) ⇒ Object
Adds an appropritate provenance statement with the given URI and saves the resource.
Methods included from Invalidatable
#invalidate!, #invalidated?, #invalidated_at_time, #was_invalidated_by
Methods included from Resource
#delete!, #etag, #http_head, #ldp_connection, #modified_date
Instance Method Details
#exists? ⇒ Boolean Also known as: exist?
Returns false if this resource does not ex.
18 19 20 21 |
# File 'lib/krikri/ldp/rdf_source.rb', line 18 def exists? return false if node? super end |
#get(*args) ⇒ Object
GETs the LDP resource from #rdf_subject and resets this object’s RDF::Graph to match the one returned from the LDP server.
52 53 54 55 56 |
# File 'lib/krikri/ldp/rdf_source.rb', line 52 def get(*args) result = super reload_ldp result end |
#rdf_source ⇒ self
60 61 62 |
# File 'lib/krikri/ldp/rdf_source.rb', line 60 def rdf_source self end |
#save ⇒ Object
this may leave the resource’s graph out of sync with the LDP endpoint since the endpoint may add management triples when saving.
PUTs the LDP resource named in #rdf_subject, populating it’s content (graph) from the object’s RDF::Graph.
31 32 33 34 |
# File 'lib/krikri/ldp/rdf_source.rb', line 31 def save(*) result = super(dump(:ttl)) result end |
#save_and_reload(*args) ⇒ Object
Saves and forces reload. This updates the graph with any management triples added by the LDP endpoint.
41 42 43 44 45 |
# File 'lib/krikri/ldp/rdf_source.rb', line 41 def save_and_reload(*args) result = save(*args) get({}, true) result end |
#save_with_provenance(activity_uri) ⇒ Object
Assuming a Marmotta LDP server, there are version URIs available (via Memento) which could be used for a direct PROV implementation. Consider options for doing that either alongside or in place of this approach.
Adds an appropritate provenance statement with the given URI and saves the resource.
This method treats RDFSources as stateful resources. This is in conflict with the PROV model, which assumes each revision is its own Resource. The internal predicate ‘dpla:wasRevisedBy` is used for non-generating revisions of stateful RDFSources.
85 86 87 88 89 |
# File 'lib/krikri/ldp/rdf_source.rb', line 85 def save_with_provenance(activity_uri) predicate = exists? ? REVISED_URI : GENERATED_URI self << RDF::Statement(self, predicate, activity_uri) save end |