Class: Valkyrie::Persistence::Postgres::Persister
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Postgres::Persister
- Defined in:
- lib/valkyrie/persistence/postgres/persister.rb
Overview
Persister for Postgres MetadataAdapter.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
-
#delete(resource:) ⇒ Valkyrie::Resource
Deletes a resource persisted within the database.
-
#initialize(adapter:) ⇒ Persister
constructor
A new instance of Persister.
-
#save(resource:) ⇒ Valkyrie::Resource
Persists a resource within the database.
-
#save_all(resources:) ⇒ Array<Valkyrie::Resource>
Persists a set of resources within the database.
-
#wipe! ⇒ Object
Deletes all resources of a specific Valkyrie Resource type persisted in the database.
Constructor Details
#initialize(adapter:) ⇒ Persister
Returns a new instance of Persister.
11 12 13 |
# File 'lib/valkyrie/persistence/postgres/persister.rb', line 11 def initialize(adapter:) @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/valkyrie/persistence/postgres/persister.rb', line 7 def adapter @adapter end |
Instance Method Details
#delete(resource:) ⇒ Valkyrie::Resource
Deletes a resource persisted within the database
46 47 48 49 50 |
# File 'lib/valkyrie/persistence/postgres/persister.rb', line 46 def delete(resource:) orm_object = resource_factory.from_resource(resource: resource) orm_object.delete resource end |
#save(resource:) ⇒ Valkyrie::Resource
Persists a resource within the database
20 21 22 23 24 25 26 |
# File 'lib/valkyrie/persistence/postgres/persister.rb', line 20 def save(resource:) orm_object = resource_factory.from_resource(resource: resource) orm_object.save! resource_factory.to_resource(object: orm_object) rescue ActiveRecord::StaleObjectError raise Valkyrie::Persistence::StaleObjectError, "The object #{resource.id} has been updated by another process." end |
#save_all(resources:) ⇒ Array<Valkyrie::Resource>
Persists a set of resources within the database
33 34 35 36 37 38 39 40 41 |
# File 'lib/valkyrie/persistence/postgres/persister.rb', line 33 def save_all(resources:) resource_factory.orm_class.transaction do resources.map do |resource| save(resource: resource) end end rescue Valkyrie::Persistence::StaleObjectError raise Valkyrie::Persistence::StaleObjectError, "One or more resources have been updated by another process." end |
#wipe! ⇒ Object
Deletes all resources of a specific Valkyrie Resource type persisted in
the database
54 55 56 |
# File 'lib/valkyrie/persistence/postgres/persister.rb', line 54 def wipe! resource_factory.orm_class.delete_all end |