Module: Krikri::LDP::Invalidatable
- Included in:
- RdfSource, OriginalRecord
- Defined in:
- lib/krikri/ldp/invalidatable.rb
Overview
Implements invalidation for ‘Krikri::LDP::Resource`s. This is different from deletion, in that the resource continues to respond `200 OK`, and return the representation, Nothing is removed from the LDP server.
Works as a mixin to ‘Krikri::LDP::Resource`, assuming an implementation of `#rdf_source`, which may simply return `self`.
Constant Summary collapse
- INVALIDATED_BY_URI =
RDF::PROV.wasInvalidatedBy
- INVALIDATED_TIME_URI =
RDF::PROV.invalidatedAtTime
Instance Method Summary collapse
-
#invalidate!(activity_uri = nil, ignore_invalid = false) ⇒ void
Invalidates the resource by marking it with a ‘prov:invalidatedAtTime`.
-
#invalidated? ⇒ Boolean
‘true` if the resource has been marked invalidated.
-
#invalidated_at_time ⇒ DateTime?
The time this resource was marked invalidated; gives ‘nil` if the resource has not been invalidated.
-
#was_invalidated_by ⇒ RDF::URI?
The activity responsible for invalidating the resource.
Instance Method Details
#invalidate!(activity_uri = nil, ignore_invalid = false) ⇒ void
This method returns an undefined value.
Invalidates the resource by marking it with a ‘prov:invalidatedAtTime`. If an `RDF::Term` is passed as the first argument, that term is used as the value of `prov:wasInvalidatedBy`.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/krikri/ldp/invalidatable.rb', line 55 def invalidate!(activity_uri = nil, ignore_invalid = false) raise "Cannot invalidate #{rdf_subject}, does not exist." unless exists? # force a reload unless we have cached an invalidatedAtTime rdf_source.get({}, true) unless invalidated? # we check invalidated again in case the reload came back invalid if invalidated? return if ignore_invalid raise "Cannot invalidate #{rdf_subject}, already invalid." end uri = RDF::URI(rdf_subject) rdf_source << [uri, INVALIDATED_BY_URI, activity_uri] unless activity_uri.nil? rdf_source << [uri, INVALIDATED_TIME_URI, DateTime.now] rdf_source.save end |
#invalidated? ⇒ Boolean
Returns ‘true` if the resource has been marked invalidated.
77 78 79 |
# File 'lib/krikri/ldp/invalidatable.rb', line 77 def invalidated? !invalidated_at_time.nil? end |
#invalidated_at_time ⇒ DateTime?
if two invalidatedAtTimes exist, we may get either of them back!
Returns the time this resource was marked invalidated; gives ‘nil` if the resource has not been invalidated.
86 87 88 89 |
# File 'lib/krikri/ldp/invalidatable.rb', line 86 def invalidated_at_time time = first_property(INVALIDATED_TIME_URI) time.nil? ? nil : time.object end |
#was_invalidated_by ⇒ RDF::URI?
if two wasInvalidatedBys exist, we may get either of them back!
Returns the activity responsible for invalidating the resource.
96 97 98 |
# File 'lib/krikri/ldp/invalidatable.rb', line 96 def was_invalidated_by first_property(INVALIDATED_BY_URI) end |