Class: Valkyrie::Persistence::Solr::Persister
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Solr::Persister
- Defined in:
- lib/valkyrie/persistence/solr/persister.rb
Overview
Persister for Solr MetadataAdapter.
Most methods are delegated to Repository
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
-
#delete(resource:) ⇒ Object
Delete a resource.
-
#initialize(adapter:) ⇒ Persister
constructor
A new instance of Persister.
-
#repository(resources) ⇒ Valkyrie::Persistence::Solr::Repository
Constructs a Solr::Repository object for a set of Valkyrie Resources.
-
#save(resource:, external_resource: false) ⇒ Valkyrie::Resource, Boolean
Save a single resource.
-
#save_all(resources:) ⇒ Array<Valkyrie::Resource>, Boolean
Save a batch of resources.
- #valid_for_save?(resource) ⇒ Boolean
-
#wipe! ⇒ Object
Removes all data from the persistence backend.
Constructor Details
#initialize(adapter:) ⇒ Persister
Returns a new instance of Persister.
13 14 15 |
# File 'lib/valkyrie/persistence/solr/persister.rb', line 13 def initialize(adapter:) @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/valkyrie/persistence/solr/persister.rb', line 8 def adapter @adapter end |
Instance Method Details
#delete(resource:) ⇒ Object
Delete a resource.
40 41 42 |
# File 'lib/valkyrie/persistence/solr/persister.rb', line 40 def delete(resource:) repository([resource]).delete.first end |
#repository(resources) ⇒ Valkyrie::Persistence::Solr::Repository
Constructs a Solr::Repository object for a set of Valkyrie Resources
53 54 55 |
# File 'lib/valkyrie/persistence/solr/persister.rb', line 53 def repository(resources) Valkyrie::Persistence::Solr::Repository.new(resources: resources, persister: self) end |
#save(resource:, external_resource: false) ⇒ Valkyrie::Resource, Boolean
Save a single resource.
19 20 21 22 23 24 25 26 |
# File 'lib/valkyrie/persistence/solr/persister.rb', line 19 def save(resource:, external_resource: false) if write_only? repository([resource]).persist else raise Valkyrie::Persistence::ObjectNotFoundError, "The object #{resource.id} is previously persisted but not found at save time." unless external_resource || valid_for_save?(resource) repository([resource]).persist.first end end |
#save_all(resources:) ⇒ Array<Valkyrie::Resource>, Boolean
Save a batch of resources.
35 36 37 |
# File 'lib/valkyrie/persistence/solr/persister.rb', line 35 def save_all(resources:) repository(resources).persist end |
#valid_for_save?(resource) ⇒ Boolean
28 29 30 31 |
# File 'lib/valkyrie/persistence/solr/persister.rb', line 28 def valid_for_save?(resource) return true unless resource.persisted? # a new resource query_service.find_by(id: resource.id).present? # a persisted resource must be found end |
#wipe! ⇒ Object
Removes all data from the persistence backend.
45 46 47 48 |
# File 'lib/valkyrie/persistence/solr/persister.rb', line 45 def wipe! connection.delete_by_query("*:*") connection.commit end |