Class: Hyrax::FileMetadata

Inherits:
Valkyrie::Resource
  • Object
show all
Includes:
Hydra::Works::MimeTypes
Defined in:
app/models/hyrax/file_metadata.rb

Defined Under Namespace

Modules: Use

Constant Summary collapse

GENERIC_MIME_TYPE =
'application/octet-stream'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(file:) ⇒ Object

Deprecated.

Use #new instead; for removal in 4.0.0



130
131
132
133
134
135
# File 'app/models/hyrax/file_metadata.rb', line 130

def self.for(file:)
  Deprecation.warn "#{self.class}##{__method__} is deprecated; use #new instead."
  new(label: file.original_filename,
      original_filename: file.original_filename,
      mime_type: file.content_type)
end

Instance Method Details

#content#to_s

Deprecated.

get content from #file instead

Returns:

  • (#to_s)


171
172
173
174
175
176
177
# File 'app/models/hyrax/file_metadata.rb', line 171

def content
  Deprecation.warn('This convienince method has been deprecated. ' \
                   'Retrieve the file from the storage adapter instead.')
  file.read
rescue Valkyrie::StorageAdapter::FileNotFound
  ''
end

#download_idObject



159
160
161
# File 'app/models/hyrax/file_metadata.rb', line 159

def download_id
  id
end

#extracted_file?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'app/models/hyrax/file_metadata.rb', line 151

def extracted_file?
  type.include?(Use::EXTRACTED_TEXT)
end

#fileValkyrie::StorageAdapter::File

Returns:

  • (Valkyrie::StorageAdapter::File)

Raises:

  • (Valkyrie::StorageAdapter::AdapterNotFoundError)

    if no adapter could be found matching the file_identifier’s scheme

  • (Valkyrie::StorageAdapter::FileNotFound)

    when the file can’t be found in the registered adapter



186
187
188
189
190
# File 'app/models/hyrax/file_metadata.rb', line 186

def file
  Valkyrie::StorageAdapter
    .adapter_for(id: file_identifier)
    .find_by(id: file_identifier)
end

#original_file?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'app/models/hyrax/file_metadata.rb', line 139

def original_file?
  type.include?(Use::ORIGINAL_FILE)
end

#thumbnail_file?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'app/models/hyrax/file_metadata.rb', line 145

def thumbnail_file?
  type.include?(Use::THUMBNAIL)
end

#titleObject



155
156
157
# File 'app/models/hyrax/file_metadata.rb', line 155

def title
  label
end

#valid?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'app/models/hyrax/file_metadata.rb', line 163

def valid?
  file.valid?(size: size.first, digests: { sha256: checksum&.first&.sha256 })
end