Class: Hyrax::Transactions::Steps::FileMetadataDelete
- Inherits:
-
Object
- Object
- Hyrax::Transactions::Steps::FileMetadataDelete
- 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
- #call(resource) ⇒ Dry::Monads::Result
-
#initialize(persister: Hyrax.persister, storage_adapter: Hyrax.storage_adapter, publisher: Hyrax.publisher) ⇒ FileMetadataDelete
constructor
A new instance of FileMetadataDelete.
Constructor Details
#initialize(persister: Hyrax.persister, storage_adapter: Hyrax.storage_adapter, publisher: Hyrax.publisher) ⇒ FileMetadataDelete
Returns a new instance of FileMetadataDelete.
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
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 |