Class: Hyrax::VisibilityIntentionApplicator

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/visibility_intention_applicator.rb

Overview

Applies a ‘VisibilityIntention` to a repository object.

Defined Under Namespace

Classes: InvalidIntentionError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(intention:) ⇒ VisibilityIntentionApplicator

Returns a new instance of VisibilityIntentionApplicator.

Parameters:



13
14
15
# File 'app/services/hyrax/visibility_intention_applicator.rb', line 13

def initialize(intention:)
  self.intention = intention
end

Instance Attribute Details

#intentionVisibilityIntention

Returns:



9
10
11
# File 'app/services/hyrax/visibility_intention_applicator.rb', line 9

def intention
  @intention
end

Class Method Details

.apply(intention) ⇒ VisibilityIntentionApplicator

Parameters:

Returns:



21
22
23
# File 'app/services/hyrax/visibility_intention_applicator.rb', line 21

def self.apply(intention)
  new(intention: intention)
end

Instance Method Details

#apply_to(model:) ⇒ Object Also known as: to

Parameters:

  • model (Object)

    an object; this probably needs to be leasable, embargoable, has visibility, and an AdminSet/PermissionTemplate.



28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/hyrax/visibility_intention_applicator.rb', line 28

def apply_to(model:)
  if intention.wants_embargo?
    raise InvalidIntentionError unless intention.valid_embargo?
    model.apply_embargo(*intention.embargo_params)
  elsif intention.wants_lease?
    raise InvalidIntentionError unless intention.valid_lease?
    model.apply_lease(*intention.lease_params)
  else
    model.visibility = intention.visibility
  end
end