Class: Hyrax::Transactions::Steps::CheckForEmptyAdminSet
- Inherits:
-
Object
- Object
- Hyrax::Transactions::Steps::CheckForEmptyAdminSet
- Defined in:
- lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
Overview
Validates emptiness of the AdministrativeSet; gives ‘Success` when empty and `Failure` otherwise.
Use this step to guard against destroying AdminSets with member objects.
Instance Method Summary collapse
- #call(admin_set) ⇒ Dry::Monads::Result
-
#initialize(query_service: Hyrax.query_service) ⇒ CheckForEmptyAdminSet
constructor
A new instance of CheckForEmptyAdminSet.
Constructor Details
#initialize(query_service: Hyrax.query_service) ⇒ CheckForEmptyAdminSet
Returns a new instance of CheckForEmptyAdminSet.
17 18 19 |
# File 'lib/hyrax/transactions/steps/check_for_empty_admin_set.rb', line 17 def initialize(query_service: Hyrax.query_service) @query_service = query_service end |
Instance Method Details
#call(admin_set) ⇒ Dry::Monads::Result
25 26 27 28 29 30 31 32 |
# File 'lib/hyrax/transactions/steps/check_for_empty_admin_set.rb', line 25 def call(admin_set) members = @query_service .find_inverse_references_by(property: :admin_set_id, resource: admin_set) return Failure["Administrative set cannot be deleted as it is not empty", members] if members.any? Success(admin_set) end |