Sha256: 7e16c7e6cdc553263bb06569f39712a41492dc84ea4c71a405a7418732af601d

Contents?: true

Size: 1.02 KB

Versions: 13

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true
require 'dry/monads'

module Hyrax
  module Transactions
    module Steps
      ##
      # Validates emptiness of the {Hyrax::AdministrativeSet}; gives `Success`
      # when empty and `Failure` otherwise.
      #
      # Use this step to guard against destroying AdminSets with member objects.
      class CheckForEmptyAdminSet
        include Dry::Monads[:result]

        ##
        # @param [#find_inverse_references_by] query_service
        def initialize(query_service: Hyrax.query_service)
          @query_service = query_service
        end

        ##
        # @param [Hyrax::AdministrativeSet] admin_set
        #
        # @return [Dry::Monads::Result]
        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
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-5.0.0.rc1 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-3.6.0 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-4.0.0 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-4.0.0.rc3 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-4.0.0.rc2 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-4.0.0.rc1 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-3.5.0 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-4.0.0.beta2 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-3.4.2 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-4.0.0.beta1 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-3.4.1 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb
hyrax-3.4.0 lib/hyrax/transactions/steps/check_for_empty_admin_set.rb