Module: ActiveFedora::AttachedFiles
- Extended by:
 - ActiveSupport::Concern
 
- Included in:
 - Base
 
- Defined in:
 - lib/active_fedora/attached_files.rb
 
Instance Method Summary collapse
- 
  
    
      #add_file(file, opts)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Attach the given stream/string to object.
 - 
  
    
      #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
 - #contains_assertions ⇒ Object
 - 
  
    
      #declared_attached_files  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns only the attached_files that are declared with ‘contains’.
 - 
  
    
      #load_attached_files  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Load any undeclared relationships or has_subresource relationships.
 - 
  
    
      #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_file(file, opts) ⇒ Object
Attach the given stream/string to object
      78 79 80 81 82 83 84  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 78 def add_file(file, opts) find_or_create_child_resource(opts[:path], opts[:prefix]).tap do |node| node.content = file node.mime_type = opts[:mime_type] node.original_name = opts[:original_name] end end  | 
  
#attach_file(file, file_path, _opts = {}) ⇒ String
Add an ActiveFedora::File to the object.
      55 56 57 58 59  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 55 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
      30 31 32  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 30 def clear_attached_files @attached_files = nil end  | 
  
#contains_assertions ⇒ Object
      34 35 36  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 34 def contains_assertions resource.query({ subject: resource, predicate: ::RDF::Vocab::LDP.contains }).objects.map(&:to_s) end  | 
  
#declared_attached_files ⇒ Object
Returns only the attached_files that are declared with ‘contains’
      10 11 12 13 14 15 16  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 10 def declared_attached_files result = {} attached_files.reflections.keys.each do |k| result[k] = attached_files[k] end result end  | 
  
#load_attached_files ⇒ Object
Load any undeclared relationships or has_subresource relationships. These are non-idiomatic LDP because we are going to find the subresource by knowing it’s subpath ahead of time. Does nothing if this object is using idiomatic basic containment, by declaring ‘is_a_container`
      41 42 43 44 45 46 47 48  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 41 def load_attached_files return if reflections[:contains] && reflections[:contains].macro == :is_a_container 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.
      62 63 64  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 62 def attached_files.select { |_k, ds| ds. }.values end  | 
  
#serialize_attached_files ⇒ Object
      5 6 7  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 5 def serialize_attached_files declared_attached_files.each_value(&:serialize!) end  | 
  
#undeclared_files ⇒ Object
      86 87 88  | 
    
      # File 'lib/active_fedora/attached_files.rb', line 86 def undeclared_files @undeclared_files ||= [] end  |