Class: Hyrax::Transactions::CreateWork

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/transactions/create_work.rb

Overview

Note:

This is an experimental replacement for the actor stack's `#create` stack. In time, we hope this will have feature parity with that stack, along with improved architecture, error handling, readability, and customizability. While this develops, please provide feedback.

A transaction for creating a Work ready for use in Hyrax. Handles ensuring admin sets and permission templates are present, and setting system managed dates prior to save.

Examples:

Creating a work transactionally

work   = MyWork.new(title: ['Comet in Moominland'])
result = Hyrax::Transactions::CreateWork.call(work)
result.success? => true

Handling errors with procedural style

work   = MyWork.new # invalid work (no title)
result = Hyrax::Transactions::CreateWork.call(work)
result.success? => false

result.failure # => failure description or object

Handling errors with `#or`

work   = MyWork.new # invalid work (no title)

Hyrax::Transactions::CreateWork
  .call(work)
  .or { |error| handle_error(error) }

See Also:

Since:

  • 2.4.0