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

destroy() { || ... } click to toggle source

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
Also aliased as: destroy!
destroy!(&block)
Alias for: destroy
destroyed?() click to toggle source

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

@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
graph() click to toggle source

@return [RDF::Graph]

# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 69
def graph
  @graph ||= RDF::Graph.new
end
graph=(graph) click to toggle source

@param graph [RDF::Graph] @return [RDF::Graph]

# File lib/active_triples/persistence_strategies/persistence_strategy.rb, line 63
def graph=(graph)
  @graph = graph
end
persist!() click to toggle source

@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
persisted?() click to toggle source

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

@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