class Ddr::Derivatives::MultiresImage

Public Class Methods

generatable?(object) click to toggle source
# File lib/ddr/derivatives/multires_image.rb, line 4
def self.generatable?(object)
  object.can_have_multires_image? &&
      object.has_content? &&
      (object.content_type == "image/tiff" || object.content_type == "image/jpeg")
end
has_derivative?(object) click to toggle source
# File lib/ddr/derivatives/multires_image.rb, line 10
def self.has_derivative?(object)
  object.has_multires_image?
end

Public Instance Methods

delete!(object) click to toggle source
# File lib/ddr/derivatives/multires_image.rb, line 14
def delete!(object)
  object.multires_image_file_path = nil
  object.save
end

Protected Instance Methods

output_file_name(object) click to toggle source
# File lib/ddr/derivatives/multires_image.rb, line 25
def output_file_name(object)
  basename = if object.content.original_name.present?
               bname = File.basename(object.content.original_name, '.*')
               Ddr::Utils.sanitize_filename(bname)
             else
               "multires_image"
             end
  "#{basename}.#{generator.class.output_extension}"
end
output_path(object) click to toggle source
# File lib/ddr/derivatives/multires_image.rb, line 21
def output_path(object)
  File.join(create_external_file_path!, output_file_name(object))
end
store(object, output_path) click to toggle source
# File lib/ddr/derivatives/multires_image.rb, line 35
def store(object, output_path)
  object.multires_image_file_path = output_path
  object.save!
end

Private Instance Methods

create_external_file_path!() click to toggle source
# File lib/ddr/derivatives/multires_image.rb, line 42
def create_external_file_path!
  file_path = generate_external_file_path
  FileUtils.mkdir_p(file_path)
  file_path
end
generate_external_directory_subpath() click to toggle source
# File lib/ddr/derivatives/multires_image.rb, line 57
def generate_external_directory_subpath
  subdir = SecureRandom.uuid
  m = Ddr::Models.external_file_subpath_regexp.match(subdir)
  raise "File name does not match external file subpath pattern: #{file_name}" unless m
  subpath_segments = m.to_a[1..-1]
  File.join *subpath_segments, subdir
end
generate_external_file_path() click to toggle source

Generates a new external file storage location

> {external_file_store}/1/e/69/1e691815-0631-4f9b-8e23-2dfb2eec9c70

# File lib/ddr/derivatives/multires_image.rb, line 53
def generate_external_file_path
  File.join(Ddr::Models.multires_image_external_file_store, generate_external_directory_subpath)
end