module ActiveFedora::AttachedFiles
def accessor_name(file_path)
def accessor_name(file_path) file_path.gsub('-', '_') end
def add_datastream(datastream, opts={})
def add_datastream(datastream, opts={}) attach_file(datastream, opts) end
def add_file(file, *args)
(**opts)
-
:original_name
(String
) -- The original name of the file (used for Content-Disposition) -
:mime_type
(String
) -- The Mime-Type of the file -
:prefix
(String
) -- The path prefix (for auto-generated path) -
:path
(String
) -- The file path
Parameters:
-
args
(Hash
) -- options: :dsid, :prefix, :mime_type -
file
(IO, String
) -- the file to add
def add_file(file, *args) opts = if args.size == 1 args.first else Deprecation.warn AttachedFiles, "The second option to add_file should be a hash. Passing the file path is deprecated and will be removed in active-fedora 10.0.", caller { path: args[0], original_name: args[1], mime_type: args[2] } end if opts[:dsid] Deprecation.warn AttachedFiles, "The :dsid option to add_file is deprecated and will be removed in active-fedora 10.0. Use :path instead", caller opts[:path] = opts[:dsid] end find_or_create_child_resource(opts[:path], opts[:prefix]).tap do |node| node.content = file node.mime_type = if opts[:mimeType] Deprecation.warn AttachedFiles, "The :mimeType option to add_file is deprecated and will be removed in active-fedora 10.0. Use :mime_type instead", caller opts[:mimeType] else opts[:mime_type] end node.original_name = opts[:original_name] end end
def add_file_datastream(file, opts={})
def add_file_datastream(file, opts={}) Deprecation.warn AttachedFiles, "add_file_datastream is deprecated and will be removed in active-fedora 10.0. Use add_file instead" add_file(file, opts) end
def attach_file(file, file_path, opts={})
-
(String)
- path of the added datastream
Parameters:
-
opts
(Hash
) -- -
file_path
(String
) -- -
file
(ActiveFedora::File
) --
def attach_file(file, file_path, opts={}) create_singleton_association(file_path) attached_files[file_path] = file file_path end
def attached_files
Attached files that have been modified in memory are given preference over
saved to fedora, the persisted files will be included.
Returns all known attached files for the object. If the object has been
def attached_files @attached_files ||= FilesHash.new(self) end
def clear_attached_files
def clear_attached_files @attached_files = nil end
def clear_datastreams
def clear_datastreams clear_attached_files end
def contains_assertions
def contains_assertions resource.query(subject: resource, predicate: Ldp.contains).objects.map(&:to_s) end
def create_singleton_association(file_path)
def create_singleton_association(file_path) self.undeclared_files << file_path.to_sym association = Associations::BasicContainsAssociation.new(self, Reflection::AssociationReflection.new(:contains, file_path, {class_name: 'ActiveFedora::File'}, self.class)) @association_cache[file_path.to_sym] = association self.singleton_class.send :define_method, accessor_name(file_path) do @association_cache[file_path.to_sym].reader end association end
def datastreams
def datastreams attached_files end
def ds_specs
def ds_specs self.class.child_resource_reflections end
def find_or_create_child_resource(path, prefix)
def find_or_create_child_resource(path, prefix) association = association(path.to_sym) if path association ||= begin file_path = FilePathBuilder.build(self, path, prefix) create_singleton_association(file_path) end association.reader end
def load_attached_files
def load_attached_files contains_assertions.each do |file_uri| path = file_uri.to_s.sub(uri + '/', '') next if association(path.to_sym) create_singleton_association(path) end end
def metadata_streams
-
(Array)
- all attached files that return true for `metadata?` and are not Rels-ext
def metadata_streams attached_files.select { |k, ds| ds.metadata? }.values end
def serialize_attached_files
def serialize_attached_files attached_files.each_value {|file| file.serialize! } end
def undeclared_files
def undeclared_files @undeclared_files ||= [] end