Sha256: d7b3ca0293b609956f8ee5b4a5d5c9a812ff0ddaadd05debadfe0afe0fd61b94
Contents?: true
Size: 1.91 KB
Versions: 1
Compression:
Stored size: 1.91 KB
Contents
module Hyrax class DerivativePath attr_reader :id, :destination_name class << self # Path on file system where derivative file is stored # @param [ActiveFedora::Base or String] object either the AF object or its id # @param [String] destintation_name def derivative_path_for_reference(object, destination_name) new(object, destination_name).derivative_path end # @param [ActiveFedora::Base or String] object either the AF object or its id # @return [Array<String>] Array of paths to derivatives for this object. def derivatives_for_reference(object) new(object).all_paths end end # @param [ActiveFedora::Base, String] object either the AF object or its id # @param [String] destination_name def initialize(object, destination_name = nil) @id = object.is_a?(String) ? object : object.id @destination_name = destination_name.gsub(/^original_file_/, '') if destination_name end def derivative_path "#{path_prefix}-#{file_name}" end def all_paths Dir.glob(root_path.join("*")).select do |path| path.start_with?(path_prefix.to_s) end end private # @return [String] Returns the root path where derivatives will be generated into. def root_path Pathname.new(derivative_path).dirname end # @return <Pathname> Full prefix of the path for object. def path_prefix Pathname.new(Hyrax.config.derivatives_path).join(pair_path) end def pair_path id.split('').each_slice(2).map(&:join).join('/') end def file_name return unless destination_name destination_name + extension end def extension case destination_name when 'thumbnail' ".#{MIME::Types.type_for('jpg').first.extensions.first}" else ".#{destination_name}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
test_hyrax-0.0.1.alpha | app/services/hyrax/derivative_path.rb |