Class: Hyrax::Transactions::Steps::SaveWork

Inherits:
Object
  • Object
show all
Includes:
Dry::Transaction::Operation
Defined in:
lib/hyrax/transactions/steps/save_work.rb

Overview

A `dry-transaction` step that saves an input work.

Examples:

saving a work

step = Hyrax::Transactions::Steps::SaveWork.new
work = MyWork.new(title: ['Comet in Moominland'])

step.call(work) # => Success

handling error cases

step = Hyrax::Transactions::Steps::SaveWork.new
work = MyWork.new(title: [:invalid_title])

step.call(work).or { |err| puts err.messages }

Since:

  • 2.4.0

Instance Method Summary collapse

Instance Method Details

#call(work) ⇒ Dry::Monads::Result

Returns `Failure` if the work fails to save; `Success(input)`, otherwise.

Parameters:

Returns:

  • (Dry::Monads::Result)

    `Failure` if the work fails to save; `Success(input)`, otherwise.

Since:

  • 2.4.0


29
30
31
# File 'lib/hyrax/transactions/steps/save_work.rb', line 29

def call(work)
  work.save ? Success(work) : Failure(work.errors)
end