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