Class: ActiveStorageValidations::ASVAttachableAdapter
- Inherits:
-
Object
- Object
- ActiveStorageValidations::ASVAttachableAdapter
- Defined in:
- lib/active_storage_validations/asv_attachable_adapter.rb
Overview
Wraps a Rails attachable so callers do not repeat the type-dispatch case tree.
Must not be named Attachable: ActiveStorageValidations is included into
Active Record, so include Attachable in an app model under this namespace
would resolve to this class instead of the app's concern.
Supported representations: ActiveStorage::Blob, ActionDispatch::Http::UploadedFile, Rack::Test::UploadedFile, Hash, File, Pathname, and a signed blob id (String).
Defined Under Namespace
Classes: Base, Blob, FileLike, HashIo, Path, SignedId, Unsupported, Uploaded
Class Method Summary collapse
-
.filename_for(file) ⇒ Object
Filename for error options.
- .wrap(attachable, file_supported:) ⇒ Object
Class Method Details
.filename_for(file) ⇒ Object
Filename for error options. Unknown types return nil (never raise). File / Pathname are always accepted here so a validation error can name the file even on Rails versions that cannot attach them.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_storage_validations/asv_attachable_adapter.rb', line 20 def self.filename_for(file) case file when ActiveStorage::Attached, ActiveStorage::Attachment file.blob&.filename else return unless known?(file) wrap(file, file_supported: true).filename end end |
.wrap(attachable, file_supported:) ⇒ Object
13 14 15 |
# File 'lib/active_storage_validations/asv_attachable_adapter.rb', line 13 def self.wrap(attachable, file_supported:) handler_class_for(attachable).new(attachable, file_supported: file_supported) end |