Class: Plutonium::Wizard::Attachments::Resolved

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(source, token) ⇒ Resolved

Returns a new instance of Resolved.

Parameters:

  • source

    the backend object (AS Blob or Shrine UploadedFile).

  • token (String)

    the ORIGINAL staged token — what the hidden preview field re-posts to preserve the upload across a Back/re-submit, and what execute assigns to the model attachment.



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_typeObject



216
# File 'lib/plutonium/wizard/attachments.rb', line 216

def content_type = @source.try(:content_type) || @source.try(:mime_type)

#extensionObject



220
# File 'lib/plutonium/wizard/attachments.rb', line 220

def extension = @source.try(:extension).presence || File.extname(filename).delete(".").presence

#filenameObject



214
# File 'lib/plutonium/wizard/attachments.rb', line 214

def filename = (@source.try(:filename) || @source.try(:original_filename)).to_s

#present?Boolean

Returns:

  • (Boolean)


222
# File 'lib/plutonium/wizard/attachments.rb', line 222

def present? = true

#representable?Boolean

Returns:

  • (Boolean)


218
# File 'lib/plutonium/wizard/attachments.rb', line 218

def representable? = @source.try(:representable?) || content_type.to_s.start_with?("image/")

#signed_idObject

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)