Class: Hyrax::Transactions::Steps::RemoveFileSetFromWork

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(query_service: Hyrax.query_service, persister: Hyrax.persister) ⇒ RemoveFileSetFromWork

Returns a new instance of RemoveFileSetFromWork.

Parameters:

  • query_service (Valkyrie::QueryService) (defaults to: Hyrax.query_service)

Since:

  • 2.4.0



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

Parameters:

Returns:

  • (Dry::Monads::Result)

Since:

  • 2.4.0



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