Class: Hyrax::Transactions::Steps::ApplyVisibility

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

Overview

A `dry-transaction` step that interprets visibility/lease/embargo from passed arguments.

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

#call(work, visibility: nil, release_date: nil, during: nil, after: nil) ⇒ Dry::Monads::Result

Returns `Failure` if there is no `PermissionTemplate` for the input; `Success(input)`, otherwise.

Parameters:

  • work (Hyrax::WorkBehavior)
  • visibility (String) (defaults to: nil)
  • release_date (String) (defaults to: nil)
  • during (String) (defaults to: nil)
  • after (String) (defaults to: nil)

Returns:

  • (Dry::Monads::Result)

    `Failure` if there is no `PermissionTemplate` for the input; `Success(input)`, otherwise.

Since:

  • 3.0.0


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hyrax/transactions/steps/apply_visibility.rb', line 22

def call(work, visibility: nil, release_date: nil, during: nil, after: nil)
  return Success(work) if visibility.blank?

  intention = Hyrax::VisibilityIntention.new(visibility: visibility,
                                             release_date: release_date,
                                             during: during,
                                             after: after)

  Hyrax::VisibilityIntentionApplicator.apply(intention).to(model: work)

  Success(work)
rescue Hyrax::VisibilityIntentionApplicator::InvalidIntentionError => err
  Failure(err)
end