module Krikri::LDP::RdfSource

Adds simple LDP persistence to ActiveTriples::Resource classes @see ActiveTriples::Resource

@see www.w3.org/TR/ldp/#ldprs

Constants

GENERATED_URI
REVISED_URI

Public Instance Methods

exist?()
Alias for: exists?
exists?() click to toggle source

@return [Boolean] false if this resource does not ex @see Krikri::LDP::Resource#exists?

Calls superclass method Krikri::LDP::Resource#exists?
# File lib/krikri/ldp/rdf_source.rb, line 18
def exists?
  return false if node?
  super
end
Also aliased as: exist?
get(*args) click to toggle source

GETs the LDP resource from rdf_subject and resets this object's RDF::Graph to match the one returned from the LDP server.

@see Krikri::LDP::Resource#get

Calls superclass method Krikri::LDP::Resource#get
# File lib/krikri/ldp/rdf_source.rb, line 52
def get(*args)
  result = super
  reload_ldp
  result
end
rdf_source() click to toggle source

@return [self]

# File lib/krikri/ldp/rdf_source.rb, line 60
def rdf_source
  self
end
save(*) click to toggle source

PUTs the LDP resource named in rdf_subject, populating it's content (graph) from the object's RDF::Graph.

@see Krikri::LDP::Resource#save @note this may leave the resource's graph out of sync with the LDP

endpoint since the endpoint may add management triples when saving.
Calls superclass method Krikri::LDP::Resource#save
# File lib/krikri/ldp/rdf_source.rb, line 31
def save(*)
  result = super(dump(:ttl))
  result
end
save_and_reload(*args) click to toggle source

Saves and forces reload. This updates the graph with any management triples added by the LDP endpoint.

@see save

# 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) click to toggle source

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.

@todo 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.

@param activity_uri [#to_term] the URI of the prov:Activity to mark as

generating or revising the saved resource.

@see save

@see www.w3.org/TR/prov-primer/ @see www.w3.org/TR/2013/REC-prov-o-20130430/

# 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

Private Instance Methods

reload_ldp() click to toggle source

Clears the RDF::Graph and repopulates it from the http body. Forces text encoding to UTF-8 before passing to the `RDF::Reader`.

@return [void]

@see www.w3.org/TR/turtle/#sec-mime for info about Turtle encoding @see www.w3.org/TR/ldp/#h-ldprs-get-turtle for info about LDP GET

and Turtle.
# File lib/krikri/ldp/rdf_source.rb, line 102
def reload_ldp
  return reload unless !node? && exists?
  clear
  self << RDF::Reader.for(:ttl).new(@http_cache.body.force_encoding('UTF-8'))
end