Class: Hyrax::Transactions::Steps::DeleteAllFileSets
- Inherits:
-
Object
- Object
- Hyrax::Transactions::Steps::DeleteAllFileSets
- Defined in:
- lib/hyrax/transactions/steps/delete_all_file_sets.rb
Overview
Deletes a resource’s member FileSets from the persister, returning a ‘Dry::Monads::Result` (`Success`|`Failure`).
Instance Method Summary collapse
- #call(resource, user: nil) ⇒ Dry::Monads::Result
-
#initialize(query_service: Hyrax.query_service, persister: Hyrax.persister, publisher: Hyrax.publisher) ⇒ DeleteAllFileSets
constructor
A new instance of DeleteAllFileSets.
Constructor Details
#initialize(query_service: Hyrax.query_service, persister: Hyrax.persister, publisher: Hyrax.publisher) ⇒ DeleteAllFileSets
Returns a new instance of DeleteAllFileSets.
17 18 19 20 21 |
# File 'lib/hyrax/transactions/steps/delete_all_file_sets.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, user: nil) ⇒ Dry::Monads::Result
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hyrax/transactions/steps/delete_all_file_sets.rb', line 28 def call(resource, user: nil) return Failure(:resource_not_persisted) unless resource.persisted? @query_service.custom_queries.find_child_file_sets(resource: resource).each do |file_set| return Failure[:failed_to_delete_file_set, file_set] unless Hyrax::Transactions::Container['file_set.destroy'] .with_step_args('file_set.remove_from_work' => { user: user }, 'file_set.delete' => { user: user }) .call(file_set).success? rescue ::Ldp::Gone nil end Success(resource) end |