Class: ActiveTriples::RepositoryStrategy
- Inherits:
-
Object
- Object
- ActiveTriples::RepositoryStrategy
- Includes:
- PersistenceStrategy
- Defined in:
- lib/active_triples/persistence_strategies/repository_strategy.rb
Overview
Persistence strategy for projecting ‘RDFSource` to `RDF::Repositories`.
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#destroy ⇒ Object
Deletes the resource from the repository.
-
#erase_old_resource ⇒ Object
Clear out any old assertions in the repository about this node or statement thus preparing to receive the updated assertions.
-
#initialize(source) ⇒ RepositoryStrategy
constructor
A new instance of RepositoryStrategy.
-
#persist! ⇒ true
Persists the resource to the repository.
-
#reload ⇒ Boolean
Repopulates the graph from the repository.
-
#repository ⇒ RDF::Repository
The RDF::Repository that the resource will project itself on when persisting.
Methods included from PersistenceStrategy
#destroyed?, #graph, #graph=, #persisted?
Constructor Details
#initialize(source) ⇒ RepositoryStrategy
Returns a new instance of RepositoryStrategy.
15 16 17 |
# File 'lib/active_triples/persistence_strategies/repository_strategy.rb', line 15 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/active_triples/persistence_strategies/repository_strategy.rb', line 10 def source @source end |
Instance Method Details
#destroy ⇒ Object
Deletes the resource from the repository.
22 23 24 |
# File 'lib/active_triples/persistence_strategies/repository_strategy.rb', line 22 def destroy super { source.clear } end |
#erase_old_resource ⇒ Object
Clear out any old assertions in the repository about this node or statement thus preparing to receive the updated assertions.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_triples/persistence_strategies/repository_strategy.rb', line 29 def erase_old_resource if source.node? repository.statements.each do |statement| repository.send(:delete_statement, statement) if statement.subject == source end else repository.delete [source.to_term, nil, nil] end end |
#persist! ⇒ true
Persists the resource to the repository
44 45 46 47 48 |
# File 'lib/active_triples/persistence_strategies/repository_strategy.rb', line 44 def persist! erase_old_resource repository << source @persisted = true end |
#reload ⇒ Boolean
Repopulates the graph from the repository.
54 55 56 57 58 |
# File 'lib/active_triples/persistence_strategies/repository_strategy.rb', line 54 def reload source << repository.query(subject: source) @persisted = true unless source.empty? true end |
#repository ⇒ RDF::Repository
Returns The RDF::Repository that the resource will project itself on when persisting.
63 64 65 |
# File 'lib/active_triples/persistence_strategies/repository_strategy.rb', line 63 def repository @repository ||= set_repository end |