Class: Plutonium::Wizard::Attachments::Resolved
- Inherits:
-
Object
- Object
- Plutonium::Wizard::Attachments::Resolved
- Defined in:
- lib/plutonium/wizard/attachments.rb
Overview
A uniform view over a resolved attachment so the review display + the uppy
preview don't care whether the source is an ActiveStorage Blob
(filename/content_type/representable?) or a Shrine UploadedFile
(original_filename/mime_type, none of the AS-only methods). Exposes
exactly what those components call.
Instance Method Summary collapse
- #content_type ⇒ Object
- #extension ⇒ Object
- #filename ⇒ Object
-
#initialize(source, token) ⇒ Resolved
constructor
A new instance of Resolved.
- #present? ⇒ Boolean
- #representable? ⇒ Boolean
-
#signed_id ⇒ Object
The re-postable token, surfaced under the name the uppy input reads.
-
#url(*args) ⇒ Object
urlis lazy (called at render, inside a request, where AS url options exist) — never eager at resolve time.
Constructor Details
#initialize(source, token) ⇒ Resolved
Returns a new instance of Resolved.
202 203 204 205 |
# File 'lib/plutonium/wizard/attachments.rb', line 202 def initialize(source, token) @source = source @token = token end |
Instance Method Details
#content_type ⇒ Object
216 |
# File 'lib/plutonium/wizard/attachments.rb', line 216 def content_type = @source.try(:content_type) || @source.try(:mime_type) |
#extension ⇒ Object
220 |
# File 'lib/plutonium/wizard/attachments.rb', line 220 def extension = @source.try(:extension).presence || File.extname(filename).delete(".").presence |
#filename ⇒ Object
214 |
# File 'lib/plutonium/wizard/attachments.rb', line 214 def filename = (@source.try(:filename) || @source.try(:original_filename)).to_s |
#present? ⇒ Boolean
222 |
# File 'lib/plutonium/wizard/attachments.rb', line 222 def present? = true |
#representable? ⇒ Boolean
218 |
# File 'lib/plutonium/wizard/attachments.rb', line 218 def representable? = @source.try(:representable?) || content_type.to_s.start_with?("image/") |
#signed_id ⇒ Object
The re-postable token, surfaced under the name the uppy input reads.
212 |
# File 'lib/plutonium/wizard/attachments.rb', line 212 def signed_id = @token |
#url(*args) ⇒ Object
url is lazy (called at render, inside a request, where AS url options
exist) — never eager at resolve time.
209 |
# File 'lib/plutonium/wizard/attachments.rb', line 209 def url(*args) = @source.url(*args) |