Class: ActiveFedora::File
- Inherits:
-
Object
- Object
- ActiveFedora::File
- Extended by:
- Querying, ActiveModel::Callbacks, ActiveSupport::Autoload, ActiveTriples::Properties
- Includes:
- AttributeMethods, Callbacks, Common, Attributes, External, 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, External, Streaming
Constant Summary
Constants included from AttributeMethods
AttributeMethods::AttrNames, AttributeMethods::RESTRICTED_CLASS_METHODS
Constants included from Callbacks
Constants included from External
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?, #versions
Methods included from Persistence
#base_path_for_resource=, #delete, #destroy, #destroy!, #destroyed?, #eradicate, #persisted?, #save, #save!, #update, #update!
Methods included from External
#external_handling, #external_handling=, #external_uri, #external_uri=
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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_fedora/file.rb', line 34 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
125 126 127 |
# File 'lib/active_fedora/file.rb', line 125 def changed? super || content_changed? || end |
#check_fixity ⇒ Object
94 95 96 |
# File 'lib/active_fedora/file.rb', line 94 def check_fixity FixityService.new(@ldp_source.subject).check end |
#checksum ⇒ Object
111 112 113 |
# File 'lib/active_fedora/file.rb', line 111 def checksum ActiveFedora::Checksum.new(self) end |
#content ⇒ Object
151 152 153 |
# File 'lib/active_fedora/file.rb', line 151 def content local_or_remote_content(true) end |
#content=(string_or_io) ⇒ Object
146 147 148 149 |
# File 'lib/active_fedora/file.rb', line 146 def content=(string_or_io) content_will_change! unless @content == string_or_io @content = string_or_io end |
#content_changed? ⇒ Boolean
115 116 117 118 |
# File 'lib/active_fedora/file.rb', line 115 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
98 99 100 |
# File 'lib/active_fedora/file.rb', line 98 def datastream_will_change! attribute_will_change! :ldp_source end |
#described_by ⇒ Object
54 55 56 57 |
# File 'lib/active_fedora/file.rb', line 54 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
74 75 76 |
# File 'lib/active_fedora/file.rb', line 74 def exists! @exists = true end |
#inspect ⇒ Object
129 130 131 |
# File 'lib/active_fedora/file.rb', line 129 def inspect "#<#{self.class} uri=\"#{uri}\" >" end |
#ldp_connection ⇒ Object
59 60 61 |
# File 'lib/active_fedora/file.rb', line 59 def ldp_connection ActiveFedora.fedora.connection end |
#metadata ⇒ Object
107 108 109 |
# File 'lib/active_fedora/file.rb', line 107 def ||= ActiveFedora::WithMetadata::MetadataNode.new(self) end |
#metadata? ⇒ boolean
Override this in your concrete datastream class.
Returns does this datastream contain metadata (not file data).
135 136 137 |
# File 'lib/active_fedora/file.rb', line 135 def false end |
#metadata_changed? ⇒ Boolean
120 121 122 123 |
# File 'lib/active_fedora/file.rb', line 120 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.
65 66 67 |
# File 'lib/active_fedora/file.rb', line 65 def new_record? !@exists && ldp_source.new? end |
#refresh ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/active_fedora/file.rb', line 84 def refresh @ldp_source = build_ldp_resource_via_uri(uri) @original_name = nil @mime_type = nil @content = nil = 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
79 80 81 82 |
# File 'lib/active_fedora/file.rb', line 79 def reload return if new_record? refresh end |
#remote_content ⇒ Object
102 103 104 105 |
# File 'lib/active_fedora/file.rb', line 102 def remote_content return if new_record? @ds_content ||= retrieve_content end |
#serialize! ⇒ Object
serializes any changed data into the content field
140 |
# File 'lib/active_fedora/file.rb', line 140 def serialize!; end |
#to_solr(solr_doc = {}, _opts = {}) ⇒ Object
142 143 144 |
# File 'lib/active_fedora/file.rb', line 142 def to_solr(solr_doc = {}, _opts = {}) solr_doc end |
#uri=(uri) ⇒ Object
69 70 71 |
# File 'lib/active_fedora/file.rb', line 69 def uri=(uri) @ldp_source = build_ldp_resource_via_uri(uri) end |