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


110
111
112
113
114
# File 'app/models/hyrax/file_metadata.rb', line 110

def self.for(file:)
  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)

150
151
152
153
154
155
156
# File 'app/models/hyrax/file_metadata.rb', line 150

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


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

def download_id
  id
end

#extracted_file?Boolean

Returns:

  • (Boolean)

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

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

#fileObject


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

def file
  Hyrax.storage_adapter.find_by(id: file_identifier)
end

#original_file?Boolean

Returns:

  • (Boolean)

118
119
120
# File 'app/models/hyrax/file_metadata.rb', line 118

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

#thumbnail_file?Boolean

Returns:

  • (Boolean)

124
125
126
# File 'app/models/hyrax/file_metadata.rb', line 124

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

#titleObject


134
135
136
# File 'app/models/hyrax/file_metadata.rb', line 134

def title
  label
end

#valid?Boolean

Returns:

  • (Boolean)

142
143
144
# File 'app/models/hyrax/file_metadata.rb', line 142

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