Module: Samvera::Derivatives

Defined in:
lib/samvera/derivatives.rb,
lib/samvera/derivatives/hyrax.rb,
lib/samvera/derivatives/configuration.rb

Overview

This module separates the finding/creation of a derivative binary (via FileLocator) and applying that derivative to the FileSet (via FileApplicator).

In working on the interface and objects there is an effort to preserve backwards functionality while also allowing for a move away from that functionality.

There are three primary concepts to consider:

  • Locator

    responsible for knowing where the derivative is

  • Location

    responsible for encapsulating the location

  • Applicator

    responsible for applying the located derivative to the FileSet

The “trick” in this is in the polymorphism of the Location. Let’s say we have the following desired functionality for the thumbnail derivative:

```gherkin
Given a FileSet
When I provide a thumbnail derivative
Then I want to add that as the thumbnail for the FileSet

Given a FileSet
When I do not provide a thumbnail derivative
Then I want to generate a thumbnail
  And add the generated as the thumbnail for the FileSet
```

In the above case we would have two Locator strategies:

  • Find Existing One

  • Will Generate One (e.g. Hyrax::FileSetDerivativesService with Hydra::Derivative behavior)

And we would have two Applicator strategies:

  • Apply an Existing One

  • Generate One and Apply (e.g. Hyrax::FileSetDerivativesService with Hydra::Derivative behavior)

The Location from the first successful Locator will dictate how the ApplicatorStrategies do their work.

Defined Under Namespace

Modules: FileApplicator, FileLocator, Hyrax Classes: Configuration

Class Method Summary collapse

Class Method Details

.config {|Configuration| ... } ⇒ Configuration

Responsible for configuration of derivatives.

Examples:

Samvera::Derivative.config do |config|
  config.register(type: :thumbnail, applicators: [CustomApplicator], locators: [CustomLocator]) do |file_set|
    file_set.video? || file_set.audio? || file_set.image?
  end
end

Yields:

Returns:



73
74
75
76
77
# File 'lib/samvera/derivatives.rb', line 73

def self.config
  @config ||= Configuration.new
  yield(@config) if block_given?
  @config
end

.locate_and_apply_derivative_for(file_set:, derivative:, file_path:) ⇒ Object

Note:

As a concession to existing implementations of creating derivatives, file_path is included as a parameter.

Locate the derivative for the given :file_set and apply it to that :file_set.

Parameters:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/samvera/derivatives.rb', line 90

def self.locate_and_apply_derivative_for(file_set:, derivative:, file_path:)
  return false unless derivative.applicable_for?(file_set: file_set)

  from_location = FileLocator.call(
    file_set: file_set,
    file_path: file_path,
    derivative: derivative
  )

  FileApplicator.call(
    from_location: from_location,
    file_set: file_set,
    derivative: derivative
  )
end