Sha256: f8035ad9ba3b7629f1a45264e5d14de374e4caa43a916470b0b416a6f8987e57

Contents?: true

Size: 909 Bytes

Versions: 13

Compression:

Stored size: 909 Bytes

Contents

# frozen_string_literal: true
require 'dry/monads'

module Hyrax
  module Transactions
    module Steps
      ##
      # Add a given `::User` as the `#creator` via a ChangeSet.
      #
      # If no user is given, simply passes as a `Success`.
      #
      # @since 3.0.0
      class SetUserAsCreator
        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.creator = [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

13 entries across 13 versions & 1 rubygems

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