Class: Samvera::Derivatives::FileApplicator::Strategy Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/samvera/derivatives.rb

Overview

This class is abstract.

The purpose of this abstract class is to provide the public interface for strategies.

See Also:

  • {{.find}

Direct Known Subclasses

Hyrax::FileApplicatorStrategy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_typeObject (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_setObject (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_locationObject (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

Parameters:

  • file_set (FileSet)
  • derivative_type (#to_sym)
  • 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

Note:

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