Class: Hydra::Derivatives::PersistBasicContainedOutputFileService

Inherits:
PersistOutputFileService show all
Defined in:
lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb

Overview

This Service is an implementation of the Hydra::Derivatives::PeristOutputFileService It supports basic contained files, which is the behavior associated with Fedora 3 file datastreams that were migrated to Fedora 4 and, at the time that this class was authored, corresponds to the behavior of ActiveFedora::Base.attach_file and ActiveFedora::Base.attached_files Rename this

Class Method Summary collapse

Methods inherited from PersistOutputFileService

determine_mime_type, determine_original_name

Class Method Details

.call(content, directives) ⇒ Object

This method conforms to the signature of the .call method on Hydra::Derivatives::PeristOutputFileService

  • Persists the file within the object at destination_name

NOTE: Uses basic containment. If you want to use direct containment (ie. with PCDM) you must use a different service (ie. Hydra::Works::AddFileToGenericFile Service)

Parameters:

  • content (IO, String)

    the data to be persisted

  • directives (Hash)

    directions which can be used to determine where to persist to.

Options Hash (directives):

  • url (String)

    This can determine the path of the object.

  • format (String)

    The file extension (e.g. ‘jpg’)



16
17
18
19
20
21
22
23
# File 'lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb', line 16

def self.call(content, directives)
  file = io(content, directives)
  remote_file = retrieve_remote_file(directives)
  remote_file.content = file
  remote_file.mime_type = determine_mime_type(file)
  remote_file.original_name = determine_original_name(file)
  remote_file.save
end

.new_mime_type(extension, charset = nil) ⇒ Object



43
44
45
46
47
# File 'lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb', line 43

def self.new_mime_type(extension, charset = nil)
  fmt = mime_format(extension)
  fmt += "; charset=#{charset}" if charset
  fmt
end