Class: Samvera::Derivatives::Hyrax::ServiceShim

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

Overview

Note:

This conforms to the Hyrax::DerivativeService interface. The intention of this class is to be the sole registered Hyrax::DerivativeService.services

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_set, candidate_derivative_types: [], config: Samvera::Derivatives.config) ⇒ ServiceShim

TODO:

We will want some kind of lambda to determine the candidate_derivative_types for this file_set.

Returns a new instance of ServiceShim.

Parameters:

  • file_set (FileSet)
  • candidate_derivative_types (Array<Symbol>) (defaults to: [])

    the possible types of derivatives that we could create for this file_set.

  • config (#registry_for) (defaults to: Samvera::Derivatives.config)


20
21
22
23
24
# File 'lib/samvera/derivatives/hyrax.rb', line 20

def initialize(file_set, candidate_derivative_types: [], config: Samvera::Derivatives.config)
  @file_set = file_set
  @config = config
  @derivatives = candidate_derivative_types.map { |type| config.registry_for(type: type) }
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



30
31
32
# File 'lib/samvera/derivatives/hyrax.rb', line 30

def config
  @config
end

#derivativesArray<Samvera::Derivatives::Configuration::RegisteredType> (readonly)



29
30
31
# File 'lib/samvera/derivatives/hyrax.rb', line 29

def derivatives
  @derivatives
end

#file_setObject (readonly)

Returns the value of attribute file_set.



26
27
28
# File 'lib/samvera/derivatives/hyrax.rb', line 26

def file_set
  @file_set
end

Instance Method Details

#cleanup_derivativesObject



39
# File 'lib/samvera/derivatives/hyrax.rb', line 39

def cleanup_derivatives; end

#create_derivatives(file_path) ⇒ Object

We have two vectors of consideration for derivative generation:

  • The desired derivatives for a file_set’s parent work (e.g. the candidate derivatives)

  • The available derivatives for a file_set’s mime type



45
46
47
48
49
50
51
52
53
# File 'lib/samvera/derivatives/hyrax.rb', line 45

def create_derivatives(file_path)
  derivatives.each do |derivative|
    Samvera::Derivatives.locate_and_apply_derivative_for(
      file_set: file_set,
      file_path: file_path,
      derivative: derivative
    )
  end
end

#derivative_url(_destination_name) ⇒ Object



55
56
57
# File 'lib/samvera/derivatives/hyrax.rb', line 55

def derivative_url(_destination_name)
  ""
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/samvera/derivatives/hyrax.rb', line 32

def valid?
  # We have a file set, which also means a parent work.  I believe we always want this to be
  # valid, because we want to leverage the locator/applicator behavior instead of the
  # implicit work.
  true
end