Class: Hyrax::Transactions::Steps::RemoveFileSetFromWork
- Inherits:
-
Object
- Object
- Hyrax::Transactions::Steps::RemoveFileSetFromWork
- Defined in:
- lib/hyrax/transactions/steps/remove_file_set_from_work.rb
Overview
removes the file set from all its parents, returning a ‘Dry::Monads::Result` (`Success`|`Failure`).
there should normally be only one parent for a FileSet, but in the case that there are multiple, this step will remove the file set from all parents.
if no user is provided to attribute the removal to, the step fails immediately.
Instance Method Summary collapse
- #call(file_set, user: nil) ⇒ Dry::Monads::Result
-
#initialize(query_service: Hyrax.query_service, persister: Hyrax.persister) ⇒ RemoveFileSetFromWork
constructor
A new instance of RemoveFileSetFromWork.
Constructor Details
#initialize(query_service: Hyrax.query_service, persister: Hyrax.persister) ⇒ RemoveFileSetFromWork
Returns a new instance of RemoveFileSetFromWork.
24 25 26 27 |
# File 'lib/hyrax/transactions/steps/remove_file_set_from_work.rb', line 24 def initialize(query_service: Hyrax.query_service, persister: Hyrax.persister) @persister = persister @query_service = query_service end |
Instance Method Details
#call(file_set, user: nil) ⇒ Dry::Monads::Result
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hyrax/transactions/steps/remove_file_set_from_work.rb', line 33 def call(file_set, user: nil) return Failure('No user provided.') if user.nil? find_parents(resource: file_set).each do |parent| parent.member_ids -= [file_set.id] unlink_file_set(parent: parent, file_set: file_set) saved = @persister.save(resource: parent) Hyrax.publisher.publish('object.metadata.updated', object: saved, user: user) end Success(file_set) end |