Class: Valkyrie::Persistence::Solr::Persister

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/persistence/solr/persister.rb

Overview

Persister for Solr MetadataAdapter.

Most methods are delegated to Repository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter:) ⇒ Persister

Returns a new instance of Persister.

Parameters:


13
14
15
# File 'lib/valkyrie/persistence/solr/persister.rb', line 13

def initialize(adapter:)
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (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.

Parameters:


28
29
30
# File 'lib/valkyrie/persistence/solr/persister.rb', line 28

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

Parameters:

Returns:


41
42
43
# File 'lib/valkyrie/persistence/solr/persister.rb', line 41

def repository(resources)
  Valkyrie::Persistence::Solr::Repository.new(resources: resources, connection: connection, resource_factory: resource_factory)
end

#save(resource:) ⇒ Valkyrie::Resource

Save a single resource.

Parameters:

Returns:

  • (Valkyrie::Resource)

    The resource with an `#id` value generated by the persistence backend.

Raises:


18
19
20
# File 'lib/valkyrie/persistence/solr/persister.rb', line 18

def save(resource:)
  repository([resource]).persist.first
end

#save_all(resources:) ⇒ Array<Valkyrie::Resource>

Save a batch of resources.

Parameters:

Returns:

  • (Array<Valkyrie::Resource>)

    List of resources with an `#id` value generated by the persistence backend.

Raises:


23
24
25
# File 'lib/valkyrie/persistence/solr/persister.rb', line 23

def save_all(resources:)
  repository(resources).persist
end

#wipe!Object

Removes all data from the persistence backend.


33
34
35
36
# File 'lib/valkyrie/persistence/solr/persister.rb', line 33

def wipe!
  connection.delete_by_query("*:*")
  connection.commit
end