class ActiveFedora::File
This class represents a Fedora datastream
def attribute_will_change!(attr)
def attribute_will_change!(attr) if attr == 'content' changed_attributes['content'] = true else super end end
def behaves_like_io?(obj)
def behaves_like_io?(obj) [IO, Tempfile, StringIO].any? { |klass| obj.kind_of? klass } || (defined?(Rack) && obj.is_a?(Rack::Test::UploadedFile)) end
def changed?
def changed? super || content_changed? end
def check_fixity
def check_fixity FixityService.new(@ldp_source.subject).check end
def content_changed?
def content_changed? return true if new_record? and !local_or_remote_content(false).blank? local_or_remote_content(false) != @ds_content end
def datastream_will_change!
def datastream_will_change! attribute_will_change! :profile end
def default_mime_type
def default_mime_type 'text/plain' end
def described_by
def described_by raise "#{self} isn't persisted yet" if new_record? links['describedby'].first end
def digest
def digest response = metadata.ldp_source.graph.query(predicate: ActiveFedora::RDF::Fcrepo4.digest) response.map(&:object) end
def dirty_size
def dirty_size content.size if changed? && content.respond_to?(:size) end
def empty?
def empty? !has_content? end
def exists!
def exists! @exists = true end
def fetch_mime_type
def fetch_mime_type ldp_source.head.headers['Content-Type'] end
def fetch_original_name_from_headers
def fetch_original_name_from_headers return if new_record? m = ldp_source.head.headers['Content-Disposition'].match(/filename="(?<filename>[^"]*)";/) URI.decode(m[:filename]) end
def freeze
def freeze @frozen = true end
def frozen?
def frozen? !!@frozen end
def has_content?
def has_content? size && size > 0 end
def initialize(parent_or_url_or_hash = nil, path=nil, options={})
-
options
(Hash
) -- -
path
(String
) -- the path partial relative to the resource -
parent_or_url_or_hash
(ActiveFedora::Base, String, Hash, NilClass
) -- the parent resource or the URI of this resource
def initialize(parent_or_url_or_hash = nil, path=nil, options={}) case parent_or_url_or_hash when Hash content = '' @ldp_source = Ldp::Resource::BinarySource.new(ldp_connection, nil, content, ActiveFedora.fedora.host + ActiveFedora.fedora.base_path) when nil, String #TODO this is similar to Core#build_ldp_resource content = '' @ldp_source = Ldp::Resource::BinarySource.new(ldp_connection, parent_or_url_or_hash, content, ActiveFedora.fedora.host + ActiveFedora.fedora.base_path) when ActiveFedora::Base Deprecation.warn File, "Initializing a file by passing a container is deprecated. Initialize with a uri instead. This capability will be removed in active-fedora 10.0" uri = if parent_or_url_or_hash.uri.kind_of?(::RDF::URI) && parent_or_url_or_hash.uri.value.empty? nil else "#{parent_or_url_or_hash.uri}/#{path}" end @ldp_source = Ldp::Resource::BinarySource.new(ldp_connection, uri, nil, ActiveFedora.fedora.host + ActiveFedora.fedora.base_path) else raise "The first argument to #{self} must be a String or an ActiveFedora::Base. You provided a #{parent_or_url.class}" end @attributes = {}.with_indifferent_access end
def inspect
def inspect "#<#{self.class} uri=\"#{uri}\" >" end
def ldp_connection
def ldp_connection ActiveFedora.fedora.connection end
def ldp_source
def ldp_source @ldp_source || raise("NO source") end
def links
def links @links ||= Ldp::Response.links(ldp_source.head) end
def metadata
def metadata @metadata ||= ActiveFedora::WithMetadata::MetadataNode.new(self) end
def metadata?
-
(boolean)
- does this datastream contain metadata (not file data)
Other tags:
- Abstract: - Override this in your concrete datastream class.
def metadata? false end
def mime_type
def mime_type @mime_type ||= fetch_mime_type unless new_record? @mime_type || default_mime_type end
def new_record?
If this file have a parent with ldp#contains, we know it is not new.
def new_record? !@exists && ldp_source.new? end
def original_name
def original_name @original_name ||= fetch_original_name_from_headers end
def original_name= name
def original_name= name @original_name = name end
def persisted_size
def persisted_size ldp_source.head.headers['Content-Length'].to_i unless new_record? end
def prefix(path)
The string to prefix all solr fields with. Override this method if you want
def prefix(path) path ? "#{path.underscore}__" : '' end
def reload
def reload return if new_record? reset end
def remote_content
def remote_content return if new_record? @ds_content ||= retrieve_content end
def reset
def reset @ldp_source = Ldp::Resource::BinarySource.new(ldp_connection, uri) @original_name = nil @mime_type = nil @content = nil @metadata = nil end
def serialize!
def serialize! end
def size
def size dirty_size || persisted_size end
def to_solr(solr_doc={}, opts={})
def to_solr(solr_doc={}, opts={}) solr_doc end
def uri
def uri ldp_source.subject end
def uri= uri
def uri= uri @ldp_source = Ldp::Resource::BinarySource.new(ldp_connection, uri, '', ActiveFedora.fedora.host + ActiveFedora.fedora.base_path) end