module ActiveTriples::PersistenceStrategy
@abstract defines the basic interface for persistence of {RDFSource}‘s.
A ‘PersistenceStrategy` has an underlying resource which should be an `RDFSource` or equivalent. Strategies can be injected into `RDFSource` instances at runtime to change the target datastore, repository, or object the instance syncs its graph with on save and reload operations.
@example Changing a PersistenceStrategy
at runtime
source = ActiveTriples::Resource.new source.persistence_strategy # => #<ActiveTriples::RepositoryStrategy:...> source.set_persistence_strategy(MyStrategy) source.persistence_strategy # => #<ActiveTriples::MyStrategy:...>
Public Instance Methods
Deletes the resource from the datastore / repository.
@yield prior to persisting, yields to allow a block that performs
deletions in the persisted graph(s).
@return [Boolean] true if the resource was sucessfully destroyed
# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 25 def destroy(&block) yield if block_given? persist! @destroyed = true end
Indicates if the Resource
has been destroyed.
@return [true, false]
# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 37 def destroyed? @destroyed ||= false end
@abstract Clear out any old assertions in the datastore / repository about this node or statement thus preparing to receive the updated assertions.
@return [Boolean]
# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 79 def erase_old_resource raise NotImplementedError, 'Abstract method #erase_old_resource is unimplemented' end
@return [RDF::Graph]
# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 69 def graph @graph ||= RDF::Graph.new end
@param graph [RDF::Graph] @return [RDF::Graph]
# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 63 def graph=(graph) @graph = graph end
@abstract save the resource according to the strategy and set the
@persisted flag to `true`
@see persisted?
@return [true] true if the save did not error
# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 56 def persist! raise NotImplementedError, 'Abstract method #persist! is unimplemented' end
Indicates if the resource is persisted to the datastore / repository
@return [Boolean] true if persisted; else false.
# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 45 def persisted? @persisted ||= false end
@abstract Repopulate the in-memory graph from the persisted graph
@return [Boolean]
# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 88 def reload raise NotImplementedError, 'Abstract method #reload is unimplemented' end