Class: Hyrax::LeaseManager

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

Overview

Provides utilities for managing the lifecycle of an `Hyrax::Lease` on a `Hyrax::Resource`.

Defined Under Namespace

Classes: NotEnforcableError, NotReleasableError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, query_service: Hyrax.query_service) ⇒ LeaseManager

Returns a new instance of LeaseManager.

Parameters:


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

def initialize(resource:, query_service: Hyrax.query_service)
  @query_service = query_service
  self.resource  = resource
end

Instance Attribute Details

#query_serviceObject (readonly)

Returns the value of attribute query_service


16
17
18
# File 'app/services/hyrax/lease_manager.rb', line 16

def query_service
  @query_service
end

#resourceHyrax::Resource

Returns:


11
12
13
# File 'app/services/hyrax/lease_manager.rb', line 11

def resource
  @resource
end

Class Method Details

.apply_lease_for(resource:, query_service: Hyrax.query_service) ⇒ Object


26
27
28
29
# File 'app/services/hyrax/lease_manager.rb', line 26

def apply_lease_for(resource:, query_service: Hyrax.query_service)
  new(resource: resource, query_service: query_service)
    .apply
end

.apply_lease_for!(resource:, query_service: Hyrax.query_service) ⇒ Object


31
32
33
34
# File 'app/services/hyrax/lease_manager.rb', line 31

def apply_lease_for!(resource:, query_service: Hyrax.query_service)
  new(resource: resource, query_service: query_service)
    .apply!
end

.lease_for(resource:, query_service: Hyrax.query_service) ⇒ Object


36
37
38
39
# File 'app/services/hyrax/lease_manager.rb', line 36

def lease_for(resource:, query_service: Hyrax.query_service)
  new(resource: resource, query_service: query_service)
    .lease
end

.release_lease_for(resource:, query_service: Hyrax.query_service) ⇒ Object


41
42
43
44
# File 'app/services/hyrax/lease_manager.rb', line 41

def release_lease_for(resource:, query_service: Hyrax.query_service)
  new(resource: resource, query_service: query_service)
    .release
end

.release_lease_for!(resource:, query_service: Hyrax.query_service) ⇒ Object


46
47
48
49
# File 'app/services/hyrax/lease_manager.rb', line 46

def release_lease_for!(resource:, query_service: Hyrax.query_service)
  new(resource: resource, query_service: query_service)
    .release!
end

Instance Method Details

#applyBoolean

Returns:

  • (Boolean)

67
68
69
70
71
# File 'app/services/hyrax/lease_manager.rb', line 67

def apply
  return false unless under_lease?

  resource.visibility = lease.visibility_during_lease
end

#apply!void

This method returns an undefined value.

Raises:


76
77
78
# File 'app/services/hyrax/lease_manager.rb', line 76

def apply!
  apply || raise(NotEnforcableError)
end

#copy_lease_to(target:) ⇒ Boolean

Copies and applies the lease to a new (target) resource.

Parameters:

Returns:

  • (Boolean)

58
59
60
61
62
63
# File 'app/services/hyrax/lease_manager.rb', line 58

def copy_lease_to(target:)
  return false unless under_lease?

  target.lease = Lease.new(clone_attributes)
  self.class.apply_lease_for(resource: target)
end

#enforced?Boolean

Returns:

  • (Boolean)

82
83
84
# File 'app/services/hyrax/lease_manager.rb', line 82

def enforced?
  lease.visibility_during_lease.to_s == resource.visibility
end

#leaseHyrax::Lease

Returns:


88
89
90
# File 'app/services/hyrax/lease_manager.rb', line 88

def lease
  resource.lease || Lease.new
end

#releaseBoolean

Returns:

  • (Boolean)

94
95
96
97
98
99
# File 'app/services/hyrax/lease_manager.rb', line 94

def release
  return false if under_lease?
  return true if lease.visibility_after_lease.nil?

  resource.visibility = lease.visibility_after_lease
end

#release!void

This method returns an undefined value.


103
104
105
# File 'app/services/hyrax/lease_manager.rb', line 103

def release!
  release || raise(NotReleasableError)
end

#under_lease?Boolean

Returns:

  • (Boolean)

109
110
111
# File 'app/services/hyrax/lease_manager.rb', line 109

def under_lease?
  lease.active?
end