Class: Fields::File

Inherits:
Field
  • Object
show all
Defined in:
app/models/iron/fields/file.rb

Instance Method Summary collapse

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_attachmentsObject



28
29
30
31
32
# File 'app/models/iron/fields/file.rb', line 28

def export_attachments
  return [] unless file.attached?

  [ file.blob ]
end

#export_valueObject



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: export_attachment_path }
end

#image?Boolean

Returns:



34
35
36
# File 'app/models/iron/fields/file.rb', line 34

def image?
  file.attached? && file.blob.content_type&.start_with?("image/")
end

#valueObject



18
19
20
# File 'app/models/iron/fields/file.rb', line 18

def value
  file.attached? ? file : nil
end