Class: Samvera::Derivatives::FileApplicator::Strategy Abstract
- Inherits:
-
Object
- Object
- Samvera::Derivatives::FileApplicator::Strategy
- Defined in:
- lib/samvera/derivatives.rb
Overview
The purpose of this abstract class is to provide the public interface for strategies.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#derivative_type ⇒ Object
readonly
Returns the value of attribute derivative_type.
-
#file_set ⇒ Object
readonly
Returns the value of attribute file_set.
-
#from_location ⇒ Object
readonly
Returns the value of attribute from_location.
Class Method Summary collapse
Instance Method Summary collapse
- #apply! ⇒ Object
-
#initialize(file_set:, derivative_type:, from_location:) ⇒ Strategy
constructor
A new instance of Strategy.
Constructor Details
#initialize(file_set:, derivative_type:, from_location:) ⇒ Strategy
Returns a new instance of Strategy.
202 203 204 205 206 |
# File 'lib/samvera/derivatives.rb', line 202 def initialize(file_set:, derivative_type:, from_location:) @file_set = file_set @derivative_type = derivative_type @from_location = from_location end |
Instance Attribute Details
#derivative_type ⇒ Object (readonly)
Returns the value of attribute derivative_type.
207 208 209 |
# File 'lib/samvera/derivatives.rb', line 207 def derivative_type @derivative_type end |
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
207 208 209 |
# File 'lib/samvera/derivatives.rb', line 207 def file_set @file_set end |
#from_location ⇒ Object (readonly)
Returns the value of attribute from_location.
207 208 209 |
# File 'lib/samvera/derivatives.rb', line 207 def from_location @from_location end |
Class Method Details
.apply!(file_set:, derivative_type:, from_location:) ⇒ Object
198 199 200 |
# File 'lib/samvera/derivatives.rb', line 198 def self.apply!(file_set:, derivative_type:, from_location:) new(file_set: file_set, derivative_type: derivative_type, from_location: from_location).apply! end |
Instance Method Details
#apply! ⇒ Object
What’s going on with this logic? To continue to leverage Hyrax::FileSetDerivativesService, we want to let that wrapped service (as a FromLocation) to do it’s original work. However, we might have multiple strategies in play for application. That case is when we want to first check for an existing thumbnail and failing that generate the thumbnail. The from_location could either be the found thumbnail…or it could be the wrapped Hyrax::FileSetDerivativesService that will create the thumbnail and write it to the location. The two applicator strategies in that case would be the wrapper and logic that will write the found file to the correct derivative path.
218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/samvera/derivatives.rb', line 218 def apply! if delegate_apply_to_given_from_location? return false unless from_location.respond_to?(:apply!) from_location.apply!(file_set: file_set, derivative_type: derivative_type) else return false if from_location.respond_to?(:apply!) perform_apply! end end |