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
- #image? ⇒ Boolean
- #value ⇒ Object
Instance Method Details
#content_value=(value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'app/models/iron/fields/file.rb', line 7 def content_value=(value) @content_errors = nil if value.nil? self.file = nil 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
28 29 30 31 32 |
# File 'app/models/iron/fields/file.rb', line 28 def return [] unless file.attached? [ file.blob ] end |
#export_value ⇒ Object
22 23 24 25 26 |
# File 'app/models/iron/fields/file.rb', line 22 def export_value return { type: "file", value: nil } unless file.attached? { type: "file", value: } end |
#image? ⇒ Boolean
34 35 36 |
# File 'app/models/iron/fields/file.rb', line 34 def image? file.attached? && file.blob.content_type&.start_with?("image/") end |
#value ⇒ Object
18 19 20 |
# File 'app/models/iron/fields/file.rb', line 18 def value file.attached? ? file : nil end |