Sha256: 0b1eaf480eafc2c8fae44becc4acb7a65acc632600fc85b275cf0116b6f60a97
Contents?: true
Size: 1.25 KB
Versions: 39
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true module ActiveStorage class Attached::Changes::CreateMany # :nodoc: attr_reader :name, :record, :attachables def initialize(name, record, attachables) @name, @record, @attachables = name, record, Array(attachables) blobs.each(&:identify_without_saving) attachments end def attachments @attachments ||= subchanges.collect(&:attachment) end def blobs @blobs ||= subchanges.collect(&:blob) end def upload subchanges.each(&:upload) end def save assign_associated_attachments reset_associated_blobs end private def subchanges @subchanges ||= attachables.collect { |attachable| build_subchange_from(attachable) } end def build_subchange_from(attachable) ActiveStorage::Attached::Changes::CreateOneOfMany.new(name, record, attachable) end def assign_associated_attachments record.public_send("#{name}_attachments=", persisted_or_new_attachments) end def reset_associated_blobs record.public_send("#{name}_blobs").reset end def persisted_or_new_attachments attachments.select { |attachment| attachment.persisted? || attachment.new_record? } end end end
Version data entries
39 entries across 37 versions & 5 rubygems