Class: Hyrax::Transactions::ApplyChangeSet

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

Overview

Applies and saves a ‘ChangeSet`.

This transaction is intended to ensure appropriate results for a Hyrax model when saving changes from a ‘ChangeSet`. For example: it will set the system-managed metadata like modified date.

If your application has custom system managed metadata, this is an appropriate place to inject that behavior.

This will also validate the ‘ChangeSet`. Which validations to use is delegated on the `ChangeSet` itself.

Examples:

Applying a ChangeSet to a Work

work = Hyrax::Work.new
change_set = Hyrax::ChangeSet.for(work)
change_set.title = ['Comet in Moominland']

transaction = Hyrax::Transactions::ApplyChangeSet.new
result = transaction.call(change_set) # => Success(#<Hyrax::Work ...>)

result.bind(&:persisted?) => true

persisted = result.value_or { raise 'oh no!' } # safe unwrap
persisted.title      # => ['Comet in Moominland']

Since:

  • 3.0.0

Constant Summary collapse

DEFAULT_STEPS =

Since:

  • 3.0.0

['change_set.set_modified_date',
'change_set.set_uploaded_date_unless_present',
'change_set.validate',
'change_set.save'].freeze

Instance Attribute Summary

Attributes inherited from Transaction

#container, #steps

Instance Method Summary collapse

Methods inherited from Transaction

#call, #with_step_args

Constructor Details

#initialize(container: Container, steps: DEFAULT_STEPS) ⇒ ApplyChangeSet

Returns a new instance of ApplyChangeSet.

See Also:

Since:

  • 3.0.0



42
43
44
# File 'lib/hyrax/transactions/apply_change_set.rb', line 42

def initialize(container: Container, steps: DEFAULT_STEPS)
  super
end