Module: ActiveTriples::PersistenceStrategy Abstract

Included in:
ParentStrategy, RepositoryStrategy
Defined in:
lib/active_triples/persistence_strategies/persistence_strategy.rb

Overview

This module is 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.

Examples:

Changing a PersistenceStrategy at runtime

source = ActiveTriples::Resource.new
source.persistence_strategy # => #<ActiveTriples::RepositoryStrategy:...>

source.set_persistence_strategy(MyStrategy)
source.persistence_strategy # => #<ActiveTriples::MyStrategy:...>

Instance Method Summary collapse

Instance Method Details

#destroy { ... } ⇒ Boolean Also known as: destroy!

Deletes the resource from the datastore / repository.

Yields:

  • prior to persisting, yields to allow a block that performs deletions in the persisted graph(s).

Returns:

  • (Boolean)

    true if the resource was sucessfully destroyed



25
26
27
28
29
30
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 25

def destroy(&block)
  yield if block_given?

  persist!
  @destroyed = true
end

#destroyed?true, false

Indicates if the Resource has been destroyed.

Returns:

  • (true, false)


37
38
39
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 37

def destroyed?
  @destroyed ||= false
end

#erase_old_resourceBoolean

This method is abstract.

Clear out any old assertions in the datastore / repository

about this node or statement thus preparing to receive the updated assertions.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


79
80
81
82
# 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

#graphRDF::Graph

Returns:

  • (RDF::Graph)


69
70
71
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 69

def graph
  @graph ||= RDF::Graph.new
end

#graph=(graph) ⇒ RDF::Graph

Parameters:

  • graph (RDF::Graph)

Returns:

  • (RDF::Graph)


63
64
65
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 63

def graph=(graph)
  @graph = graph
end

#persist!true

This method is abstract.

save the resource according to the strategy and set the @persisted flag to ‘true`

Returns true if the save did not error.

Returns:

  • (true)

    true if the save did not error

Raises:

  • (NotImplementedError)

See Also:



56
57
58
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 56

def persist!
  raise NotImplementedError, 'Abstract method #persist! is unimplemented'
end

#persisted?Boolean

Indicates if the resource is persisted to the datastore / repository

Returns:

  • (Boolean)

    true if persisted; else false.



45
46
47
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 45

def persisted?
  @persisted ||= false
end

#reloadBoolean

This method is abstract.

Repopulate the in-memory graph from the persisted graph

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


88
89
90
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 88

def reload
  raise NotImplementedError, 'Abstract method #reload is unimplemented'
end