Class: Hyrax::Transactions::Steps::RemoveFromMembership
- Inherits:
-
Object
- Object
- Hyrax::Transactions::Steps::RemoveFromMembership
- Defined in:
- lib/hyrax/transactions/steps/remove_from_membership.rb
Overview
Removes a collection from its members, returning a ‘Dry::Monads::Result` (`Success`|`Failure`).
Instance Method Summary collapse
- #call(collection, user: nil) ⇒ Dry::Monads::Result
-
#initialize(query_service: Hyrax.custom_queries, persister: Hyrax.persister, publisher: Hyrax.publisher) ⇒ RemoveFromMembership
constructor
A new instance of RemoveFromMembership.
Constructor Details
#initialize(query_service: Hyrax.custom_queries, persister: Hyrax.persister, publisher: Hyrax.publisher) ⇒ RemoveFromMembership
Returns a new instance of RemoveFromMembership.
17 18 19 20 21 |
# File 'lib/hyrax/transactions/steps/remove_from_membership.rb', line 17 def initialize(query_service: Hyrax.custom_queries, persister: Hyrax.persister, publisher: Hyrax.publisher) @persister = persister @query_service = query_service @publisher = publisher end |
Instance Method Details
#call(collection, user: nil) ⇒ Dry::Monads::Result
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hyrax/transactions/steps/remove_from_membership.rb', line 28 def call(collection, user: nil) return Failure(:resource_not_persisted) unless collection.persisted? return Failure(:user_not_present) if user.blank? @query_service.find_members_of(collection: collection).each do |member| member.member_of_collection_ids -= [collection.id] @persister.save(resource: member) @publisher.publish('collection.membership.updated', collection: collection, user: user) rescue StandardError nil end Success(collection) end |