Class: Hyrax::Transactions::Steps::AddToCollections

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/transactions/steps/add_to_collections.rb

Overview

Add a resource to collections via ‘ChangeSet`.

Accepts ‘:collection_ids` and never retrieves the actual collections from the persisted data. We trust that the identifiers passed refer to actual, extant collections, and that the permissions to add to collection membership have been established, or else that they’ll be validated prior to save.

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

#call(change_set, collection_ids: []) ⇒ Dry::Monads::Result

Add to collections by inserting collections to ‘ChangeSet#member_of_collection_ids`.

Parameters:

Returns:

  • (Dry::Monads::Result)

Since:

  • 3.0.0



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

def call(change_set, collection_ids: [])
  multi_membership_messages = check_multi_membership(change_set, collection_ids)
  return Failure(multi_membership_messages) if multi_membership_messages.present?

  change_set.member_of_collection_ids += collection_ids
  Success(change_set)
end