Class: Hyrax::Transactions::Steps::DeleteAllFileMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/transactions/steps/delete_all_file_metadata.rb

Overview

Deletes a resource from the persister, returning a ‘Dry::Monads::Result` (`Success`|`Failure`).

Instance Method Summary collapse

Constructor Details

#initialize(query_service: Hyrax.query_service, persister: Hyrax.persister, publisher: Hyrax.publisher) ⇒ DeleteAllFileMetadata

Returns a new instance of DeleteAllFileMetadata.

Since:

  • 2.4.0



17
18
19
20
21
# File 'lib/hyrax/transactions/steps/delete_all_file_metadata.rb', line 17

def initialize(query_service: Hyrax.query_service, persister: Hyrax.persister, publisher: Hyrax.publisher)
  @persister = persister
  @query_service = query_service
  @publisher = publisher
end

Instance Method Details

#call(resource) ⇒ Dry::Monads::Result

Parameters:

  • resource (Valkyrie::Resource)
  • the (::User)

    user resposible for the delete action

Returns:

  • (Dry::Monads::Result)

Since:

  • 2.4.0



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hyrax/transactions/steps/delete_all_file_metadata.rb', line 28

def call(resource)
  return Failure(:resource_not_persisted) unless resource.persisted?

  @query_service.custom_queries.find_files(file_set: resource).each do ||
    return Failure[:failed_to_delete_file_metadata, .id] unless
      Hyrax::Transactions::Container['file_metadata.destroy']
      .call()
      .success?
  rescue ::Ldp::Gone
    nil
  end

  Success(resource)
end