blob: af19328a610b546ec97d8374d056241b5ac51fe1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# 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)
end
def attachments
@attachments ||= subchanges.collect(&:attachment)
end
def blobs
@blobs ||= subchanges.collect(&:blob)
end
def upload
subchanges.each(&:upload)
end
def save
record.public_send("#{name}_attachments=", attachments)
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
end
end
|