module ActiveTriples::Persistable
Bundles the core interfaces used by ActiveTriples
persistence strategies to treat a graph as persistable. Specificially:
- RDF::Enumerable - RDF::Mutable
@abstract implement {#graph} as a reference to an ‘RDF::Graph` or similar.
Public Instance Methods
@see RDF::Writable.delete_statement
# File lib/active_triples/persistable.rb, line 37 def delete_statement(*args) graph.send(:delete_statement, *args) end
Removes the statements in this RDFSource’s graph from the persisted graph
@return [Boolean]
# File lib/active_triples/persistable.rb, line 61 def destroy persistence_strategy.destroy end
@return [Boolean] true if this item is destroyed
# File lib/active_triples/persistable.rb, line 68 def destroyed? persistence_strategy.destroyed? end
This gives the {RDF::Graph} which represents the current state of this resource.
@return [RDF::Graph] the underlying graph representation of the
`RDFSource`.
@see www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#change-over-time
RDF Concepts and Abstract Syntax comment on "RDF source"
# File lib/active_triples/persistable.rb, line 26 def graph persistence_strategy.graph end
@see RDF::Writable.insert_statement
# File lib/active_triples/persistable.rb, line 31 def insert_statement(*args) graph.send(:insert_statement, *args) end
Sends a persistence message to the ‘persistence_startegy`, saving the `Persistable`.
@return [Boolean]
# File lib/active_triples/persistable.rb, line 77 def persist!(opts={}) result = false return result if opts[:validate] && !valid? run_callbacks :persist do result = persistence_strategy.persist! end result end
Indicates if the resource is persisted.
@see persist @return [Boolean]
# File lib/active_triples/persistable.rb, line 91 def persisted? persistence_strategy.persisted? end
Returns the persistence strategy object that handles this object’s persistence
# File lib/active_triples/persistable.rb, line 44 def persistence_strategy @persistence_strategy || set_persistence_strategy(RepositoryStrategy) end
Repopulates the graph according to the persistence strategy
@return [Boolean]
# File lib/active_triples/persistable.rb, line 99 def reload @term_cache ||= {} persistence_strategy.reload end
Sets a persistence strategy
@param klass [Class] A class implementing the persistence strategy
interface
# File lib/active_triples/persistable.rb, line 53 def set_persistence_strategy(klass) @persistence_strategy = klass.new(self) end