Class: Plutonium::Wizard::AttachmentData
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Plutonium::Wizard::AttachmentData
- Defined in:
- lib/plutonium/wizard/attachment_data.rb
Overview
Decorates a step's typed data so ATTACHMENT fields READ as resolved,
displayable attachments (Plutonium::Wizard::Attachments::Resolved) rather than the raw staged
token string — so the step form's Uppy preview rehydrates on Back/resume
(it calls .url/.signed_id/.filename, which a bare token string can't
answer). Every other field delegates unchanged.
Read-only: the SUBMITTED value is still the token the hidden preview field
re-posts (Resolved#signed_id == the original token), so staging is
unaffected.
Class Method Summary collapse
-
.wrap(data, step) ⇒ Object
Wrap only when the step actually has an attachment field — otherwise return the data untouched, so the overwhelming majority of steps are unaffected.
Instance Method Summary collapse
-
#class ⇒ Object
Masquerade as the wrapped object's class so phlexi still infers field affordances (required marker, maxlength, …) from its validators — it reads
object.class.validators_on(...), and aSimpleDelegatorwould otherwise report its own class and drop every marker on the step. -
#initialize(data, attachment_fields) ⇒ AttachmentData
constructor
A new instance of AttachmentData.
Constructor Details
#initialize(data, attachment_fields) ⇒ AttachmentData
Returns a new instance of AttachmentData.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/plutonium/wizard/attachment_data.rb', line 22 def initialize(data, ) super(data) .each do |name, config| multiple = config.dig(:options, :multiple) define_singleton_method(name) do resolved = Attachments.resolve(__getobj__.public_send(name)) multiple ? resolved : resolved.first end end end |
Class Method Details
.wrap(data, step) ⇒ Object
Wrap only when the step actually has an attachment field — otherwise return the data untouched, so the overwhelming majority of steps are unaffected.
17 18 19 20 |
# File 'lib/plutonium/wizard/attachment_data.rb', line 17 def self.wrap(data, step) = step.inputs.select { |_name, config| Attachments.field?(config) } .any? ? new(data, ) : data end |
Instance Method Details
#class ⇒ Object
Masquerade as the wrapped object's class so phlexi still infers field
affordances (required marker, maxlength, …) from its validators — it reads
object.class.validators_on(...), and a SimpleDelegator would otherwise
report its own class and drop every marker on the step.
37 38 39 |
# File 'lib/plutonium/wizard/attachment_data.rb', line 37 def class __getobj__.class end |