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
31
32
33
34
35
36
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 25

def destroy(&block)
  yield if block_given?
  
  # Provide a warning for strategies relying on #destroy to clear the resource
  if defined? obj
    warn "DEPRECATION WARNING: #destroy implementations must now explicitly call 'source.clear'"
    obj.clear
  end
  
  persist!
  @destroyed = true
end

#destroyed?true, false

Indicates if the Resource has been destroyed.

Returns:

  • (true, false)


43
44
45
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 43

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)


72
73
74
75
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 72

def erase_old_resource
  raise NotImplementedError, 
        'Abstract method #erase_old_resource is unimplemented'
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:



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

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.



51
52
53
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 51

def persisted?
  @persisted ||= false
end

#reloadBoolean

This method is abstract.

Repopulate the in-memory graph from the persisted graph

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/active_triples/persistence_strategies/persistence_strategy.rb', line 81

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