Sha256: 5d7a404cb0b9e6cee183d04ffb0dc5888158517379352e8235b714604bbbecd7

Contents?: true

Size: 1.14 KB

Versions: 18

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true
module Hyrax
  module Transactions
    module Steps
      ##
      # A step that sets the `#collection_type_gid` in the change set.
      #
      # @since 3.2.0
      class SetCollectionTypeGid
        include Dry::Monads[:result]

        ##
        # @param [Hyrax::ChangeSet] change_set
        # @param collection_type_gid [URI::GID] global id for the collection type
        # @return [Dry::Monads::Result] `Failure` if there is no `collection_type_gid` or
        #   it can't be set to the default for the input; `Success(input)`, otherwise.
        def call(change_set, collection_type_gid: default_collection_type_gid)
          return Failure[:no_collection_type_gid, collection] unless
            change_set.respond_to?(:collection_type_gid=)
          return Success(change_set) if
            change_set.collection_type_gid.present?

          change_set.collection_type_gid = collection_type_gid
          Success(change_set)
        end

        private

        def default_collection_type_gid
          Hyrax::CollectionType.find_or_create_default_collection_type.to_global_id
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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