Class: Hyrax::EmbargoManager
- Inherits:
-
Object
- Object
- Hyrax::EmbargoManager
- Defined in:
- app/services/hyrax/embargo_manager.rb
Overview
Provides utilities for managing the lifecycle of an ‘Hyrax::Embargo` on a `Hyrax::Resource`.
The embargo terminology used here is as follows:
- "Release Date" is the day an embargo is scheduled to be released.
- "Under Embargo" means the embargo is "active"; i.e. that its release
date is today or later.
- "Applied" means the embargo's pre-release visibility has been set on
the resource.
- "Released" means the embargo's post-release visibility has been set on
the resource.
- "Enforced" means the object's visibility matches the pre-release
visibility of the embargo; i.e. the embargo has been applied,
but not released.
Note that an resource may be ‘#under_embargo?` even if the embargo is not be `#enforced?` (in this case, the application should seek to apply the embargo, e.g. via a scheduled job). Additionally, an embargo may be `#enforced?` after its release date (in this case, the application should seek to release the embargo).
Defined Under Namespace
Classes: NotEnforcableError, NotReleasableError
Instance Attribute Summary collapse
-
#query_service ⇒ Object
readonly
Returns the value of attribute query_service.
- #resource ⇒ Hyrax::Resource
Class Method Summary collapse
- .apply_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
- .apply_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Object
- .embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
- .release_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
- .release_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Object
Instance Method Summary collapse
-
#apply ⇒ Boolean
Sets the visibility of the resource to the embargo’s visibility condition.
- #apply! ⇒ void
-
#copy_embargo_to(target:) ⇒ Boolean
Copies and applies the embargo to a new (target) resource.
- #embargo ⇒ Hyrax::Embargo
- #enforced? ⇒ Boolean
-
#initialize(resource:, query_service: Hyrax.query_service) ⇒ EmbargoManager
constructor
A new instance of EmbargoManager.
-
#nullify ⇒ void
Drop the embargo by setting its release date to ‘nil`.
-
#release ⇒ Boolean
Sets the visibility of the resource to the embargo’s visibility condition.
- #release! ⇒ void
-
#under_embargo? ⇒ Boolean
Indicates whether the date range for the embargo’s applicability includes the present date.
Constructor Details
#initialize(resource:, query_service: Hyrax.query_service) ⇒ EmbargoManager
Returns a new instance of EmbargoManager.
90 91 92 93 |
# File 'app/services/hyrax/embargo_manager.rb', line 90 def initialize(resource:, query_service: Hyrax.query_service) @query_service = query_service self.resource = resource end |
Instance Attribute Details
#query_service ⇒ Object (readonly)
Returns the value of attribute query_service.
86 87 88 |
# File 'app/services/hyrax/embargo_manager.rb', line 86 def query_service @query_service end |
#resource ⇒ Hyrax::Resource
81 82 83 |
# File 'app/services/hyrax/embargo_manager.rb', line 81 def resource @resource end |
Class Method Details
.apply_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
96 97 98 99 |
# File 'app/services/hyrax/embargo_manager.rb', line 96 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .apply end |
.apply_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Object
101 102 103 104 |
# File 'app/services/hyrax/embargo_manager.rb', line 101 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .apply! end |
.embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
106 107 108 109 |
# File 'app/services/hyrax/embargo_manager.rb', line 106 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) . end |
.release_embargo_for(resource:, query_service: Hyrax.query_service) ⇒ Object
111 112 113 114 |
# File 'app/services/hyrax/embargo_manager.rb', line 111 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .release end |
.release_embargo_for!(resource:, query_service: Hyrax.query_service) ⇒ Object
116 117 118 119 |
# File 'app/services/hyrax/embargo_manager.rb', line 116 def (resource:, query_service: Hyrax.query_service) new(resource: resource, query_service: query_service) .release! end |
Instance Method Details
#apply ⇒ Boolean
Sets the visibility of the resource to the embargo’s visibility condition
139 140 141 142 143 |
# File 'app/services/hyrax/embargo_manager.rb', line 139 def apply return false unless resource.visibility = . end |
#apply! ⇒ void
This method returns an undefined value.
148 149 150 |
# File 'app/services/hyrax/embargo_manager.rb', line 148 def apply! apply || raise(NotEnforcableError) end |
#copy_embargo_to(target:) ⇒ Boolean
Copies and applies the embargo to a new (target) resource.
128 129 130 131 132 133 |
# File 'app/services/hyrax/embargo_manager.rb', line 128 def (target:) return false unless target. = Embargo.new(clone_attributes) self.class.(resource: target) end |
#embargo ⇒ Hyrax::Embargo
160 161 162 |
# File 'app/services/hyrax/embargo_manager.rb', line 160 def resource. || Embargo.new end |
#enforced? ⇒ Boolean
154 155 156 |
# File 'app/services/hyrax/embargo_manager.rb', line 154 def enforced? ..to_s == resource.visibility end |
#nullify ⇒ void
This method returns an undefined value.
Drop the embargo by setting its release date to ‘nil`.
168 169 170 171 |
# File 'app/services/hyrax/embargo_manager.rb', line 168 def nullify return unless . = nil end |
#release ⇒ Boolean
Sets the visibility of the resource to the embargo’s visibility condition. no-op if the embargo period is current.
178 179 180 181 182 183 |
# File 'app/services/hyrax/embargo_manager.rb', line 178 def release return false if return true if ..nil? resource.visibility = . end |
#release! ⇒ void
This method returns an undefined value.
189 190 191 |
# File 'app/services/hyrax/embargo_manager.rb', line 189 def release! release || raise(NotReleasableError) end |
#under_embargo? ⇒ Boolean
Returns indicates whether the date range for the embargo’s applicability includes the present date.
196 197 198 |
# File 'app/services/hyrax/embargo_manager.rb', line 196 def .active? end |