Sha256: a9679a89acb3ba52c49b28681e9ac25201dd200d633a8c9627136125081515c0

Contents?: true

Size: 913 Bytes

Versions: 25

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true
require 'dry/monads'

module Hyrax
  module Transactions
    module Steps
      ##
      # Add a given `::User` as the `#depositor` via a ChangeSet.
      #
      # If no user is given, simply passes as a `Success`.
      #
      # @since 3.0.0
      class SetUserAsDepositor
        include Dry::Monads[:result]

        ##
        # @param [Hyrax::ChangeSet] change_set
        # @param [#user_key] user
        #
        # @return [Dry::Monads::Result]
        def call(change_set, user: NullUser.new)
          change_set.depositor = user.user_key if user.user_key

          Success(change_set)
        rescue NoMethodError => err
          Failure([err.message, change_set])
        end

        ##
        # @api private
        class NullUser
          ##
          # @return [nil]
          def user_key
            nil
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

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