class ActiveStorage::Attached::Many

Public Instance Methods

attach(*attachables) click to toggle source
# File lib/active_storage/attached/many.rb, line 8
def attach(*attachables)
  @attachments = attachments | Array(attachables).flatten.collect do |attachable|
    ActiveStorage::Attachment.create!(record_gid: record.to_gid.to_s, name: name, blob: create_blob_from(attachable))
  end
end
attached?() click to toggle source
# File lib/active_storage/attached/many.rb, line 14
def attached?
  attachments.any?
end
attachments() click to toggle source
# File lib/active_storage/attached/many.rb, line 4
def attachments
  @attachments ||= ActiveStorage::Attachment.where(record_gid: record.to_gid.to_s, name: name)
end
purge() click to toggle source
# File lib/active_storage/attached/many.rb, line 18
def purge
  if attached?
    attachments.each(&:purge)
    @attachments = nil
  end
end
purge_later() click to toggle source
# File lib/active_storage/attached/many.rb, line 25
def purge_later
  if attached?
    attachments.each(&:purge_later)
    @attachments = nil
  end
end