Module: ActiveTriples::Persistable Abstract
- Extended by:
- ActiveSupport::Concern
- Includes:
- RDF::Enumerable, RDF::Mutable
- Included in:
- RDFSource
- Defined in:
- lib/active_triples/persistable.rb
Overview
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
- #delete_statement(*args) ⇒ Object
-
#destroy ⇒ Boolean
(also: #destroy!)
Removes the statements in this RDFSource’s graph from the persisted graph.
-
#destroyed? ⇒ Boolean
True if this item is destroyed.
- #each(*args) ⇒ Object
- #insert_statement(*args) ⇒ Object
-
#persist!(opts = {}) ⇒ Boolean
Sends a persistence message to the persistence_startegy, saving the RDFSource.
-
#persisted? ⇒ Boolean
Indicates if the resource is persisted.
-
#persistence_strategy ⇒ Object
Returns the persistence strategy object that handles this object’s persistence.
-
#reload ⇒ Boolean
Repopulates the graph according to the persistence strategy.
-
#set_persistence_strategy(klass) ⇒ Object
Sets a persistence strategy.
Instance Method Details
#delete_statement(*args) ⇒ Object
31 32 33 |
# File 'lib/active_triples/persistable.rb', line 31 def delete_statement(*args) graph.send(:delete_statement, *args) end |
#destroy ⇒ Boolean Also known as: destroy!
Removes the statements in this RDFSource’s graph from the persisted graph
55 56 57 |
# File 'lib/active_triples/persistable.rb', line 55 def destroy persistence_strategy.destroy end |
#destroyed? ⇒ Boolean
Returns true if this item is destroyed.
62 63 64 |
# File 'lib/active_triples/persistable.rb', line 62 def destroyed? persistence_strategy.destroyed? end |
#each(*args) ⇒ Object
19 20 21 |
# File 'lib/active_triples/persistable.rb', line 19 def each(*args) graph.each(*args) end |
#insert_statement(*args) ⇒ Object
25 26 27 |
# File 'lib/active_triples/persistable.rb', line 25 def insert_statement(*args) graph.send(:insert_statement, *args) end |
#persist!(opts = {}) ⇒ Boolean
Sends a persistence message to the persistence_startegy, saving the RDFSource.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/active_triples/persistable.rb', line 71 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.
88 89 90 |
# File 'lib/active_triples/persistable.rb', line 88 def persisted? persistence_strategy.persisted? end |
#persistence_strategy ⇒ Object
Returns the persistence strategy object that handles this object’s persistence
38 39 40 |
# File 'lib/active_triples/persistable.rb', line 38 def persistence_strategy @persistence_strategy || set_persistence_strategy(RepositoryStrategy) end |
#reload ⇒ Boolean
Repopulates the graph according to the persistence strategy
96 97 98 99 |
# File 'lib/active_triples/persistable.rb', line 96 def reload @term_cache ||= {} persistence_strategy.reload end |
#set_persistence_strategy(klass) ⇒ Object
Sets a persistence strategy
47 48 49 |
# File 'lib/active_triples/persistable.rb', line 47 def set_persistence_strategy(klass) @persistence_strategy = klass.new(self) end |