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
-
#declared_attached_files ⇒ Object
Returns only the attached_files that are declared with ‘contains’.
- #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
74 75 76 |
# File 'lib/active_fedora/attached_files.rb', line 74 def add_datastream(datastream, opts = {}) attach_file(datastream, opts) end |
#add_file(file, *args) ⇒ Object
Attach the given stream/string to object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/active_fedora/attached_files.rb', line 101 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
88 89 90 91 |
# File 'lib/active_fedora/attached_files.rb', line 88 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.
68 69 70 71 72 |
# File 'lib/active_fedora/attached_files.rb', line 68 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.
33 34 35 |
# File 'lib/active_fedora/attached_files.rb', line 33 def attached_files @attached_files ||= FilesHash.new(self) end |
#clear_attached_files ⇒ Object
42 43 44 |
# File 'lib/active_fedora/attached_files.rb', line 42 def clear_attached_files @attached_files = nil end |
#clear_datastreams ⇒ Object
46 47 48 |
# File 'lib/active_fedora/attached_files.rb', line 46 def clear_datastreams clear_attached_files end |
#contains_assertions ⇒ Object
51 52 53 |
# File 'lib/active_fedora/attached_files.rb', line 51 def contains_assertions resource.query(subject: resource, predicate: ::RDF::Vocab::LDP.contains).objects.map(&:to_s) end |
#datastreams ⇒ Object
37 38 39 |
# File 'lib/active_fedora/attached_files.rb', line 37 def datastreams attached_files end |
#declared_attached_files ⇒ Object
Returns only the attached_files that are declared with ‘contains’
19 20 21 22 23 |
# File 'lib/active_fedora/attached_files.rb', line 19 def declared_attached_files attached_files.reflections.keys.each_with_object({}) do |k, h| h[k] = attached_files[k] end 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
55 56 57 58 59 60 61 |
# File 'lib/active_fedora/attached_files.rb', line 55 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.
80 81 82 |
# File 'lib/active_fedora/attached_files.rb', line 80 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 declared_attached_files.each_value(&:serialize!) end |
#undeclared_files ⇒ Object
126 127 128 |
# File 'lib/active_fedora/attached_files.rb', line 126 def undeclared_files @undeclared_files ||= [] end |