Class: Fields::File
- Inherits:
-
Field
- Object
- Field
- Fields::File
- Defined in:
- app/models/iron/fields/file.rb
Instance Method Summary collapse
- #content_value=(value) ⇒ Object
- #export_attachments ⇒ Object
- #export_value ⇒ Object
- #filled? ⇒ Boolean
- #image? ⇒ Boolean
- #value ⇒ Object
Instance Method Details
#content_value=(value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/iron/fields/file.rb', line 7 def content_value=(value) @content_errors = nil if value.nil? self.file = nil elsif !value.is_a?(String) add_content_error("must be an upload token (signed id)") elsif value.present? self.file = ActiveStorage::Blob.find_signed!(value) end rescue ActiveSupport::MessageVerifier::InvalidSignature, ActiveRecord::RecordNotFound add_content_error("has an invalid upload token") end |
#export_attachments ⇒ Object
32 33 34 35 36 |
# File 'app/models/iron/fields/file.rb', line 32 def return [] unless file.attached? [ file.blob ] end |
#export_value ⇒ Object
26 27 28 29 30 |
# File 'app/models/iron/fields/file.rb', line 26 def export_value return { type: "file", value: nil } unless file.attached? { type: "file", value: } end |
#image? ⇒ Boolean
38 39 40 |
# File 'app/models/iron/fields/file.rb', line 38 def image? file.attached? && file.blob.content_type&.start_with?("image/") end |
#value ⇒ Object
22 23 24 |
# File 'app/models/iron/fields/file.rb', line 22 def value file.attached? ? file : nil end |