Class: ActiveFedora::File
- Inherits:
 - 
      Object
      
        
- Object
 - ActiveFedora::File
 
 
- Extended by:
 - Querying, ActiveModel::Callbacks, ActiveSupport::Autoload, ActiveTriples::Properties
 
- Includes:
 - AttributeMethods, Callbacks, Common, Attributes, Streaming, FilePersistence, Identifiable, Inheritance, Scoping, Versionable, ActiveModel::Dirty
 
- Defined in:
 - lib/active_fedora/file.rb
 
Overview
An LDP NonRDFSource. The base class for a bytestream stored in the repository.
Defined Under Namespace
Modules: Attributes, Streaming
Constant Summary
Constants included from AttributeMethods
AttributeMethods::AttrNames, AttributeMethods::RESTRICTED_CLASS_METHODS
Constants included from Callbacks
Instance Method Summary collapse
- #changed? ⇒ Boolean
 - #check_fixity ⇒ Object
 - #checksum ⇒ Object
 - #content ⇒ Object
 - #content=(string_or_io) ⇒ Object
 - #content_changed? ⇒ Boolean
 - #datastream_will_change! ⇒ Object
 - #described_by ⇒ Object
 - 
  
    
      #exists!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
If we know the record to exist (parent has LDP:contains), we can avoid unnecessary HEAD requests.
 - 
  
    
      #initialize(identifier = nil) {|self| ... } ⇒ File 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of File.
 - #inspect ⇒ Object
 - #ldp_connection ⇒ Object
 - #metadata ⇒ Object
 - 
  
    
      #metadata?  ⇒ boolean 
    
    
  
  
  
  
  
  abstract
  
  
  
    
Does this datastream contain metadata (not file data).
 - #metadata_changed? ⇒ Boolean
 - 
  
    
      #new_record?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
If this file has a parent with ldp#contains, we know it is not new.
 - #refresh ⇒ Object
 - 
  
    
      #reload  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
When restoring from previous versions, we need to reload certain attributes from Fedora.
 - #remote_content ⇒ Object
 - 
  
    
      #serialize!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
serializes any changed data into the content field.
 - #to_solr(solr_doc = {}, _opts = {}) ⇒ Object
 - #uri=(uri) ⇒ Object
 
Methods included from Querying
Methods included from Scoping
#initialize_internals_callback, #populate_with_current_scope_attributes
Methods included from Identifiable
Methods included from AttributeMethods
#[], #[]=, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #has_attribute?
Methods included from Callbacks
Methods included from Versionable
#create_version, #has_versions?, #model_type, #restore_version, #versions
Methods included from Persistence
#base_path_for_resource=, #delete, #destroy, #destroy!, #destroyed?, #eradicate, #persisted?, #save, #save!, #update, #update!
Methods included from Streaming
Methods included from Attributes
#assign_attributes, #create_date, #digest, #dirty_size, #empty?, #has_content?, #mime_type, #modified_date, #original_name, #original_name=, #persisted_size, #size
Methods included from Common
#<=>, #==, #etag, #freeze, #frozen?, #ldp_source, #readonly!, #readonly?
Constructor Details
#initialize(identifier = nil) {|self| ... } ⇒ File
Returns a new instance of File.
      32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50  | 
    
      # File 'lib/active_fedora/file.rb', line 32 def initialize(identifier = nil, &_block) identifier = identifier.delete(:id) if identifier.is_a? Hash identifier = identifier.uri if identifier.respond_to? :uri run_callbacks(:initialize) do case identifier when nil, ::RDF::URI @ldp_source = build_ldp_resource_via_uri identifier when String id = ActiveFedora::Associations::IDComposite.new([identifier], translate_uri_to_id).first @ldp_source = build_ldp_resource id else raise "The first argument to #{self} must be a Hash, String or RDF::URI. You provided a #{identifier.class}" end @local_attributes = {}.with_indifferent_access @readonly = false yield self if block_given? end end  | 
  
Instance Method Details
#changed? ⇒ Boolean
      123 124 125  | 
    
      # File 'lib/active_fedora/file.rb', line 123 def changed? super || content_changed? || end  | 
  
#check_fixity ⇒ Object
      92 93 94  | 
    
      # File 'lib/active_fedora/file.rb', line 92 def check_fixity FixityService.new(@ldp_source.subject).check end  | 
  
#checksum ⇒ Object
      109 110 111  | 
    
      # File 'lib/active_fedora/file.rb', line 109 def checksum ActiveFedora::Checksum.new(self) end  | 
  
#content ⇒ Object
      149 150 151  | 
    
      # File 'lib/active_fedora/file.rb', line 149 def content local_or_remote_content(true) end  | 
  
#content=(string_or_io) ⇒ Object
      144 145 146 147  | 
    
      # File 'lib/active_fedora/file.rb', line 144 def content=(string_or_io) content_will_change! unless @content == string_or_io @content = string_or_io end  | 
  
#content_changed? ⇒ Boolean
      113 114 115 116  | 
    
      # File 'lib/active_fedora/file.rb', line 113 def content_changed? return true if new_record? && local_or_remote_content(false).present? local_or_remote_content(false) != @ds_content end  | 
  
#datastream_will_change! ⇒ Object
      96 97 98  | 
    
      # File 'lib/active_fedora/file.rb', line 96 def datastream_will_change! attribute_will_change! :ldp_source end  | 
  
#described_by ⇒ Object
      52 53 54 55  | 
    
      # File 'lib/active_fedora/file.rb', line 52 def described_by raise "#{self} isn't persisted yet" if new_record? links['describedby'].first end  | 
  
#exists! ⇒ Object
If we know the record to exist (parent has LDP:contains), we can avoid unnecessary HEAD requests
      72 73 74  | 
    
      # File 'lib/active_fedora/file.rb', line 72 def exists! @exists = true end  | 
  
#inspect ⇒ Object
      127 128 129  | 
    
      # File 'lib/active_fedora/file.rb', line 127 def inspect "#<#{self.class} uri=\"#{uri}\" >" end  | 
  
#ldp_connection ⇒ Object
      57 58 59  | 
    
      # File 'lib/active_fedora/file.rb', line 57 def ldp_connection ActiveFedora.fedora.connection end  | 
  
#metadata ⇒ Object
      105 106 107  | 
    
      # File 'lib/active_fedora/file.rb', line 105 def @metadata ||= ActiveFedora::WithMetadata::MetadataNode.new(self) end  | 
  
#metadata? ⇒ boolean
Override this in your concrete datastream class.
Returns does this datastream contain metadata (not file data).
      133 134 135  | 
    
      # File 'lib/active_fedora/file.rb', line 133 def false end  | 
  
#metadata_changed? ⇒ Boolean
      118 119 120 121  | 
    
      # File 'lib/active_fedora/file.rb', line 118 def return false if new_record? || links['describedby'].blank? .changed? end  | 
  
#new_record? ⇒ Boolean
If this file has a parent with ldp#contains, we know it is not new. By tracking exists we prevent an unnecessary HEAD request.
      63 64 65  | 
    
      # File 'lib/active_fedora/file.rb', line 63 def new_record? !@exists && ldp_source.new? end  | 
  
#refresh ⇒ Object
      82 83 84 85 86 87 88 89 90  | 
    
      # File 'lib/active_fedora/file.rb', line 82 def refresh @ldp_source = build_ldp_resource_via_uri(uri) @original_name = nil @mime_type = nil @content = nil @metadata = nil @ds_content = nil clear_attribute_changes(changes.keys) end  | 
  
#reload ⇒ Object
When restoring from previous versions, we need to reload certain attributes from Fedora
      77 78 79 80  | 
    
      # File 'lib/active_fedora/file.rb', line 77 def reload return if new_record? refresh end  | 
  
#remote_content ⇒ Object
      100 101 102 103  | 
    
      # File 'lib/active_fedora/file.rb', line 100 def remote_content return if new_record? @ds_content ||= retrieve_content end  | 
  
#serialize! ⇒ Object
serializes any changed data into the content field
      138  | 
    
      # File 'lib/active_fedora/file.rb', line 138 def serialize!; end  | 
  
#to_solr(solr_doc = {}, _opts = {}) ⇒ Object
      140 141 142  | 
    
      # File 'lib/active_fedora/file.rb', line 140 def to_solr(solr_doc = {}, _opts = {}) solr_doc end  | 
  
#uri=(uri) ⇒ Object
      67 68 69  | 
    
      # File 'lib/active_fedora/file.rb', line 67 def uri=(uri) @ldp_source = build_ldp_resource_via_uri(uri) end  |