Class: ActiveStorage::Attached::Changes::CreateMany
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activestorage/lib/active_storage/attached/changes/create_many.rb |
Class Method Summary
Instance Attribute Summary
- #attachables readonly
- #name readonly
- #pending_uploads readonly
- #record readonly
Instance Method Summary
- #attachments
- #blobs
- #save
- #upload
- #assign_associated_attachments private
- #build_subchange_from(attachable) private
- #persisted_or_new_attachments private
- #reset_associated_blobs private
- #subchanges private
- #subchanges_without_blobs private
Constructor Details
.new(name, record, attachables, pending_uploads: []) ⇒ CreateMany
# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 7
def initialize(name, record, attachables, pending_uploads: []) @name, @record, @attachables = name, record, Array(attachables) blobs.each(&:identify_without_saving) @pending_uploads = Array(pending_uploads) + subchanges_without_blobs end
Instance Attribute Details
#attachables (readonly)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 5
attr_reader :name, :record, :attachables, :pending_uploads
#name (readonly)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 5
attr_reader :name, :record, :attachables, :pending_uploads
#pending_uploads (readonly)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 5
attr_reader :name, :record, :attachables, :pending_uploads
#record (readonly)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 5
attr_reader :name, :record, :attachables, :pending_uploads
Instance Method Details
#assign_associated_attachments (private)
[ GitHub ]#attachments
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 14
def @attachments ||= subchanges.collect(&: ) end
#blobs
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 18
def blobs @blobs ||= subchanges.collect(&:blob) end
#build_subchange_from(attachable) (private)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 36
def build_subchange_from(attachable) ActiveStorage::Attached::Changes::CreateOneOfMany.new(name, record, attachable) end
#persisted_or_new_attachments (private)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 52
def .select { || .persisted? || .new_record? } end
#reset_associated_blobs (private)
[ GitHub ]#save
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 26
def save reset_associated_blobs end
#subchanges (private)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 32
def subchanges @subchanges ||= attachables.collect { |attachable| build_subchange_from(attachable) } end
#subchanges_without_blobs (private)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 40
def subchanges_without_blobs subchanges.reject { |subchange| subchange.attachable.is_a?(ActiveStorage::Blob) } end
#upload
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_many.rb', line 22
def upload pending_uploads.each(&:upload) end