Module: ActiveFedora::AttachedFiles
- Extended by:
- ActiveSupport::Concern, Deprecation
- Included in:
- Base
- Defined in:
- lib/active_fedora/attached_files.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #add_datastream(datastream, opts = {}) ⇒ Object
-
#add_file(file, *args) ⇒ Object
Attach the given stream/string to object.
-
#add_file_datastream(file, opts = {}) ⇒ Object
File Management.
-
#attach_file(file, file_path, opts = {}) ⇒ String
Add an ActiveFedora::File to the object.
-
#attached_files ⇒ Object
Returns all known attached files for the object.
- #clear_attached_files ⇒ Object
- #clear_datastreams ⇒ Object
- #contains_assertions ⇒ Object
- #datastreams ⇒ Object
- #ds_specs ⇒ Object
- #load_attached_files ⇒ Object
-
#metadata_streams ⇒ Array
All attached files that return true for ‘metadata?` and are not Rels-ext.
- #serialize_attached_files ⇒ Object
- #undeclared_files ⇒ Object
Instance Method Details
#add_datastream(datastream, opts = {}) ⇒ Object
67 68 69 |
# File 'lib/active_fedora/attached_files.rb', line 67 def add_datastream(datastream, opts={}) attach_file(datastream, opts) end |
#add_file(file, *args) ⇒ Object
Attach the given stream/string to object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/active_fedora/attached_files.rb', line 94 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 |
#add_file_datastream(file, opts = {}) ⇒ Object
File Management
81 82 83 84 |
# File 'lib/active_fedora/attached_files.rb', line 81 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 |
#attach_file(file, file_path, opts = {}) ⇒ String
Add an ActiveFedora::File to the object.
61 62 63 64 65 |
# File 'lib/active_fedora/attached_files.rb', line 61 def attach_file(file, file_path, opts={}) create_singleton_association(file_path) attached_files[file_path] = file file_path end |
#attached_files ⇒ Object
Returns all known attached files for the object. If the object has been saved to fedora, the persisted files will be included. Attached files that have been modified in memory are given preference over the copy in Fedora.
26 27 28 |
# File 'lib/active_fedora/attached_files.rb', line 26 def attached_files @attached_files ||= FilesHash.new(self) end |
#clear_attached_files ⇒ Object
35 36 37 |
# File 'lib/active_fedora/attached_files.rb', line 35 def clear_attached_files @attached_files = nil end |
#clear_datastreams ⇒ Object
39 40 41 |
# File 'lib/active_fedora/attached_files.rb', line 39 def clear_datastreams clear_attached_files end |
#contains_assertions ⇒ Object
44 45 46 |
# File 'lib/active_fedora/attached_files.rb', line 44 def contains_assertions resource.query(subject: resource, predicate: Ldp.contains).objects.map(&:to_s) end |
#datastreams ⇒ Object
30 31 32 |
# File 'lib/active_fedora/attached_files.rb', line 30 def datastreams attached_files end |
#ds_specs ⇒ Object
9 10 11 |
# File 'lib/active_fedora/attached_files.rb', line 9 def ds_specs self.class.child_resource_reflections end |
#load_attached_files ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/active_fedora/attached_files.rb', line 48 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 |
#metadata_streams ⇒ Array
Returns all attached files that return true for ‘metadata?` and are not Rels-ext.
73 74 75 |
# File 'lib/active_fedora/attached_files.rb', line 73 def attached_files.select { |k, ds| ds. }.values end |
#serialize_attached_files ⇒ Object
14 15 16 |
# File 'lib/active_fedora/attached_files.rb', line 14 def serialize_attached_files attached_files.each_value {|file| file.serialize! } end |
#undeclared_files ⇒ Object
119 120 121 |
# File 'lib/active_fedora/attached_files.rb', line 119 def undeclared_files @undeclared_files ||= [] end |