Class: Hyrax::Transactions::Steps::FileMetadataDelete

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(persister: Hyrax.persister, storage_adapter: Hyrax.storage_adapter, publisher: Hyrax.publisher) ⇒ FileMetadataDelete

Returns a new instance of FileMetadataDelete.

Since:

  • 2.4.0



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

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

Instance Method Details

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

Parameters:

  • FileMetadata (Hyrax::FileMetadata)

    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
# File 'lib/hyrax/transactions/steps/file_metadata_delete.rb', line 28

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

  @persister.delete(resource: resource)
  @publisher.publish('file.metadata.deleted', metadata: resource)
  Valkyrie::StorageAdapter.delete(id: resource.file_identifier) if resource.file_identifier.present?

  Success(resource)
end