module ActiveFedora::File::Persistence
def content
def content local_or_remote_content(true) end
def content= string_or_io
def content= string_or_io content_will_change! unless @content == string_or_io @content = string_or_io end
def local_or_remote_content(ensure_fetch = true)
def local_or_remote_content(ensure_fetch = true) return @content if new_record? @content ||= ensure_fetch ? remote_content : @ds_content if behaves_like_io?(@content) begin @content.rewind @content.read ensure @content.rewind end else @content end @content end
def retrieve_content
def retrieve_content ldp_source.get.body end
def save(*)
def save(*) return unless content_changed? headers = { 'Content-Type'.freeze => mime_type, 'Content-Length'.freeze => content.size.to_s } headers['Content-Disposition'.freeze] = "attachment; filename=\"#{URI.encode(@original_name)}\"" if @original_name ldp_source.content = content if new_record? ldp_source.create do |req| req.headers.merge!(headers) end else ldp_source.update do |req| req.headers.merge!(headers) end end reset changed_attributes.clear end
def uploaded_file?(payload)
def uploaded_file?(payload) defined?(ActionDispatch::Http::UploadedFile) and payload.instance_of?(ActionDispatch::Http::UploadedFile) end