Module: ActiveTriples::Persistable Abstract

Extended by:
ActiveSupport::Concern
Includes:
RDF::Enumerable, RDF::Mutable
Included in:
RDFSource
Defined in:
lib/active_triples/persistable.rb

Overview

This module is abstract.

implement #graph as a reference to an ‘RDF::Graph` or similar.

Bundles the core interfaces used by ActiveTriples persistence strategies to treat a graph as persistable. Specificially:

- RDF::Enumerable
- RDF::Mutable

Instance Method Summary collapse

Instance Method Details

#delete_statement(*args) ⇒ Object

See Also:

  • RDF::Writable.delete_statement


44
45
46
# File 'lib/active_triples/persistable.rb', line 44

def delete_statement(*args)
  graph.send(:delete_statement, *args)
end

#destroyBoolean Also known as: destroy!

Removes the statements in this RDFSource’s graph from the persisted graph

Returns:

  • (Boolean)


68
69
70
# File 'lib/active_triples/persistable.rb', line 68

def destroy
  persistence_strategy.destroy
end

#destroyed?Boolean

Returns true if this item is destroyed.

Returns:

  • (Boolean)

    true if this item is destroyed



75
76
77
# File 'lib/active_triples/persistable.rb', line 75

def destroyed?
  persistence_strategy.destroyed?
end

#each(*args) ⇒ Object

See Also:

  • RDF::Enumerable.each


32
33
34
# File 'lib/active_triples/persistable.rb', line 32

def each(*args)
  graph.each(*args)
end

#graphRDF::Graph

This gives the RDF::Graph which represents the current state of this resource.

Returns:

  • (RDF::Graph)

    the underlying graph representation of the ‘RDFSource`.

See Also:



26
27
28
# File 'lib/active_triples/persistable.rb', line 26

def graph
  persistence_strategy.graph
end

#insert_statement(*args) ⇒ Object

See Also:

  • RDF::Writable.insert_statement


38
39
40
# File 'lib/active_triples/persistable.rb', line 38

def insert_statement(*args)
  graph.send(:insert_statement, *args)
end

#persist!(opts = {}) ⇒ Boolean

Sends a persistence message to the persistence_startegy, saving the RDFSource.

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
94
# File 'lib/active_triples/persistable.rb', line 84

def persist!(opts={})
  return if @persisting
  result = false
  return result if opts[:validate] && !valid?
  @persisting = true
  run_callbacks :persist do
    result = persistence_strategy.persist!
  end
  @persisting = false
  result
end

#persisted?Boolean

Indicates if the resource is persisted.

Returns:

  • (Boolean)

See Also:

  • #persist


101
102
103
# File 'lib/active_triples/persistable.rb', line 101

def persisted?
  persistence_strategy.persisted?
end

#persistence_strategyObject

Returns the persistence strategy object that handles this object’s persistence



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

def persistence_strategy
  @persistence_strategy || set_persistence_strategy(RepositoryStrategy)
end

#reloadBoolean

Repopulates the graph according to the persistence strategy

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/active_triples/persistable.rb', line 109

def reload
  @term_cache ||= {}
  persistence_strategy.reload
end

#set_persistence_strategy(klass) ⇒ Object

Sets a persistence strategy

Parameters:

  • klass (Class)

    A class implementing the persistence strategy interface



60
61
62
# File 'lib/active_triples/persistable.rb', line 60

def set_persistence_strategy(klass)
  @persistence_strategy = klass.new(self)
end