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'

Instance Method Summary collapse

Instance Method Details

#content#to_s

Deprecated.

get content from #file instead

Returns:

  • (#to_s)


164
165
166
167
168
169
170
# File 'app/models/hyrax/file_metadata.rb', line 164

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



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

def download_id
  id
end

#extracted_file?Boolean

Returns:

  • (Boolean)


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

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



179
180
181
182
183
# File 'app/models/hyrax/file_metadata.rb', line 179

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

#original_file?Boolean

Returns:

  • (Boolean)


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

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

#thumbnail_file?Boolean

Returns:

  • (Boolean)


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

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

#titleObject



148
149
150
# File 'app/models/hyrax/file_metadata.rb', line 148

def title
  label
end

#valid?Boolean

Returns:

  • (Boolean)


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

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