Class: Hyrax::Transactions::Steps::DeleteResource

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/transactions/steps/delete_resource.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, publisher: Hyrax.publisher) ⇒ DeleteResource

Returns a new instance of DeleteResource.

Since:

  • 2.4.0



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

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

Instance Method Details

#call(resource, user: nil) ⇒ Dry::Monads::Result

Parameters:

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

    user resposible for the delete action

Returns:

  • (Dry::Monads::Result)

Since:

  • 2.4.0



27
28
29
30
31
32
33
34
# File 'lib/hyrax/transactions/steps/delete_resource.rb', line 27

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

  @persister.delete(resource: resource)
  publish_changes(resource: resource, user: user)

  Success(resource)
end