Class: Hyrax::Transactions::Steps::CheckForEmptyAdminSet

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

Since:

  • 2.4.0

Instance Method Summary collapse

Constructor Details

#initialize(query_service: Hyrax.query_service) ⇒ CheckForEmptyAdminSet

Returns a new instance of CheckForEmptyAdminSet.

Parameters:

  • query_service (#find_inverse_references_by) (defaults to: Hyrax.query_service)

Since:

  • 2.4.0


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

Parameters:

Returns:

  • (Dry::Monads::Result)

Since:

  • 2.4.0


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[:admin_set_has_members, members] if members.any?

  Success(admin_set)
end