Module: Hyrax::LeaseabilityBehavior

Included in:
Forms::FileSetForm, Forms::PcdmObjectForm, Forms::ResourceBatchEditForm
Defined in:
app/forms/concerns/hyrax/leaseability_behavior.rb

Overview

A module of form behaviours for embargoes, leases, and resulting visibilities.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(descendant) ⇒ Object

rubocop:disable Metrics/AbcSize



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/forms/concerns/hyrax/leaseability_behavior.rb', line 7

def self.included(descendant) # rubocop:disable Metrics/AbcSize
  descendant.property :visibility, default: VisibilityIntention::PRIVATE, populator: :visibility_populator

  descendant.property :embargo, form: Hyrax::Forms::Embargo, populator: :embargo_populator
  descendant.property :lease, form: Hyrax::Forms::Lease, populator: :lease_populator

  # virtual properties for embargo/lease;
  descendant.property :embargo_release_date, virtual: true, prepopulator: proc { |_opts| self.embargo_release_date = model.embargo&.embargo_release_date }
  descendant.property :visibility_after_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_after_embargo = model.embargo&.visibility_after_embargo }
  descendant.property :visibility_during_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_during_embargo = model.embargo&.visibility_during_embargo }

  descendant.property :lease_expiration_date, virtual: true,  prepopulator: proc { |_opts| self.lease_expiration_date = model.lease&.lease_expiration_date }
  descendant.property :visibility_after_lease, virtual: true, prepopulator: proc { |_opts| self.visibility_after_lease = model.lease&.visibility_after_lease }
  descendant.property :visibility_during_lease, virtual: true, prepopulator: proc { |_opts| self.visibility_during_lease = model.lease&.visibility_during_lease }
end

Instance Method Details

#embargo_populatorObject



23
24
25
# File 'app/forms/concerns/hyrax/leaseability_behavior.rb', line 23

def embargo_populator(**)
  self.embargo = Hyrax::EmbargoManager.embargo_for(resource: model)
end

#lease_populatorObject



27
28
29
# File 'app/forms/concerns/hyrax/leaseability_behavior.rb', line 27

def lease_populator(**)
  self.lease = Hyrax::LeaseManager.lease_for(resource: model)
end

#visibility_populator(fragment:, doc:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/forms/concerns/hyrax/leaseability_behavior.rb', line 31

def visibility_populator(fragment:, doc:, **)
  case fragment
  when "embargo"
    self.visibility = doc['visibility_during_embargo']

    doc['embargo'] = doc.slice('visibility_after_embargo',
                               'visibility_during_embargo',
                               'embargo_release_date')
  when "lease"
    self.visibility = doc['visibility_during_lease']
    doc['lease'] = doc.slice('visibility_after_lease',
                               'visibility_during_lease',
                               'lease_expiration_date')
  else
    self.visibility = fragment
  end
end