Sha256: 0d7c9f0cd3de9d175ba355256056cf28b991d141928c8beea0d45e4a9038275a

Contents?: true

Size: 1.08 KB

Versions: 37

Compression:

Stored size: 1.08 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)
    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=", attachments)
      end

      def reset_associated_blobs
        record.public_send("#{name}_blobs").reset
      end
  end
end

Version data entries

37 entries across 37 versions & 4 rubygems

Version Path
activestorage-6.1.7.10 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.9 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.8 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.7 lib/active_storage/attached/changes/create_many.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-6.1.6.1/lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.6 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.5 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.4 lib/active_storage/attached/changes/create_many.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activestorage-6.1.6.1/lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.3 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.2 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7.1 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.7 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.6.1 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.6 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.5.1 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.5 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.4.7 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.4.6 lib/active_storage/attached/changes/create_many.rb
activestorage-6.1.4.5 lib/active_storage/attached/changes/create_many.rb