Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from projecthydra/input_object_or_string
Allow input of file name or object that knows the file name.
- Loading branch information
Showing
6 changed files
with
85 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 12 additions & 10 deletions
22
lib/hydra/derivatives/runners/active_encode_derivatives.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# For the case where the source file is a remote file, and we | ||
# don't want to download the file locally, just return the | ||
# file name or file path (or whatever we need to pass to the | ||
# encoding service so that it can find the file). | ||
|
||
module Hydra::Derivatives | ||
class RemoteSourceFile | ||
# Finds the file name of the remote source file. | ||
# @param [String, ActiveFedora::Base] String file name, or an object that has a method that will return the file name | ||
# @param [Hash] options | ||
# @option options [Symbol] :source a method that can be called on the object to retrieve the source file's name | ||
# @yield [String] the file name | ||
def self.call(object, options, &_block) | ||
source_name = options.fetch(:source, :to_s) | ||
yield(object.send(source_name)) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
|
||
class TestVideo < ActiveFedora::Base | ||
attr_accessor :remote_file_name | ||
end | ||
|
||
describe Hydra::Derivatives::ActiveEncodeDerivatives do | ||
context '.create' do | ||
let(:file_path) { 'some/path/to/my_video.mp4' } | ||
let(:video_record) { TestVideo.new(remote_file_name: file_path) } | ||
let(:options) { { source: :remote_file_name, outputs: [low_res_video] } } | ||
let(:low_res_video) { { some_key: 'some options to pass to my encoder service' } } | ||
let(:processor) { double('processor') } | ||
|
||
it 'calls the processor with the right arguments' do | ||
expect(Hydra::Derivatives::Processors::ActiveEncode).to receive(:new).with(file_path, low_res_video, output_file_service: Hydra::Derivatives::NullOutputFileService).and_return(processor) | ||
expect(processor).to receive(:process) | ||
described_class.create(video_record, options) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'spec_helper' | ||
|
||
class TestObject < ActiveFedora::Base | ||
attr_accessor :source_file_name | ||
end | ||
|
||
describe Hydra::Derivatives::RemoteSourceFile do | ||
describe '.call' do | ||
let(:file_name) { 'my_source_file.mp4' } | ||
|
||
context 'when you pass in a String file name' do | ||
let(:input_obj) { file_name } | ||
let(:options) { Hash.new } | ||
|
||
it 'it yields the file name' do | ||
expect do |blk| | ||
described_class.call(input_obj, options, &blk) | ||
end.to yield_with_args(file_name) | ||
end | ||
end | ||
|
||
context 'when you pass in an ActiveFedora::Base object ' do | ||
let(:input_obj) { TestObject.new(source_file_name: file_name) } | ||
let(:options) { { source: :source_file_name } } | ||
|
||
it 'it yields the file name' do | ||
expect do |blk| | ||
described_class.call(input_obj, options, &blk) | ||
end.to yield_with_args(file_name) | ||
end | ||
end | ||
end | ||
end |