Class: Valkyrie::Persistence::CompositePersister
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::CompositePersister
- Defined in:
- lib/valkyrie/persistence/composite_persister.rb
Overview
Wraps up multiple persisters under a common interface, to transparently persist to multiple places at once.
Instance Attribute Summary collapse
-
#persisters ⇒ Object
readonly
Returns the value of attribute persisters.
Instance Method Summary collapse
- #delete(resource:) ⇒ Object
-
#initialize(*persisters) ⇒ CompositePersister
constructor
A new instance of CompositePersister.
-
#save(resource:) ⇒ Valkyrie::Resource
The resource with an ‘#id` value generated by the persistence backend.
-
#save_all(resources:) ⇒ Array<Valkyrie::Resource>
List of resources with an ‘#id` value generated by the persistence backend.
- #wipe! ⇒ Object
Constructor Details
#initialize(*persisters) ⇒ CompositePersister
Returns a new instance of CompositePersister.
16 17 18 |
# File 'lib/valkyrie/persistence/composite_persister.rb', line 16 def initialize(*persisters) @persisters = persisters end |
Instance Attribute Details
#persisters ⇒ Object (readonly)
Returns the value of attribute persisters.
15 16 17 |
# File 'lib/valkyrie/persistence/composite_persister.rb', line 15 def persisters @persisters end |
Instance Method Details
#delete(resource:) ⇒ Object
33 34 35 |
# File 'lib/valkyrie/persistence/composite_persister.rb', line 33 def delete(resource:) persisters.inject(resource) { |m, persister| persister.delete(resource: m) } end |
#save(resource:) ⇒ Valkyrie::Resource
Returns The resource with an ‘#id` value generated by the persistence backend.
21 22 23 |
# File 'lib/valkyrie/persistence/composite_persister.rb', line 21 def save(resource:) persisters.inject(resource) { |m, persister| persister.save(resource: m) } end |
#save_all(resources:) ⇒ Array<Valkyrie::Resource>
Returns List of resources with an ‘#id` value generated by the persistence backend.
26 27 28 29 30 |
# File 'lib/valkyrie/persistence/composite_persister.rb', line 26 def save_all(resources:) resources.map do |resource| save(resource: resource) end end |
#wipe! ⇒ Object
37 38 39 |
# File 'lib/valkyrie/persistence/composite_persister.rb', line 37 def wipe! persisters.each_entry(&:wipe!) end |