Sha256: e5525eddc88413a1cd926944281abe7c1f3d3ba4cd44dca2089563054883ff3d

Contents?: true

Size: 1.22 KB

Versions: 33

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require "action_dispatch"
require "action_dispatch/http/upload"
require "active_support/core_ext/module/delegation"

module ActiveStorage
  # Abstract base class for the concrete ActiveStorage::Attached::One and ActiveStorage::Attached::Many
  # classes that both provide proxy access to the blob association for a record.
  class Attached
    attr_reader :name, :record, :dependent

    def initialize(name, record, dependent:)
      @name, @record, @dependent = name, record, dependent
    end

    private
      def create_blob_from(attachable)
        case attachable
        when ActiveStorage::Blob
          attachable
        when ActionDispatch::Http::UploadedFile, Rack::Test::UploadedFile
          ActiveStorage::Blob.create_after_upload! \
            io: attachable.open,
            filename: attachable.original_filename,
            content_type: attachable.content_type
        when Hash
          ActiveStorage::Blob.create_after_upload!(attachable)
        when String
          ActiveStorage::Blob.find_signed(attachable)
        else
          nil
        end
      end
  end
end

require "active_storage/attached/one"
require "active_storage/attached/many"
require "active_storage/attached/macros"

Version data entries

33 entries across 33 versions & 3 rubygems

Version Path
activestorage-5.2.8.1 lib/active_storage/attached.rb
activestorage-5.2.8 lib/active_storage/attached.rb
activestorage-5.2.7.1 lib/active_storage/attached.rb
activestorage-5.2.7 lib/active_storage/attached.rb
activestorage-5.2.6.3 lib/active_storage/attached.rb
activestorage-5.2.6.2 lib/active_storage/attached.rb
activestorage-5.2.6.1 lib/active_storage/attached.rb
activestorage-5.2.6 lib/active_storage/attached.rb
activestorage-5.2.4.6 lib/active_storage/attached.rb
activestorage-5.2.5 lib/active_storage/attached.rb
activestorage-5.2.4.5 lib/active_storage/attached.rb
activestorage-5.2.4.4 lib/active_storage/attached.rb
activestorage-5.2.4.3 lib/active_storage/attached.rb
activestorage-5.2.4.2 lib/active_storage/attached.rb
activestorage-5.2.4.1 lib/active_storage/attached.rb
activestorage-5.2.4 lib/active_storage/attached.rb
activestorage-5.2.4.rc1 lib/active_storage/attached.rb
spiral_form-0.1.1 vendor/bundle/gems/activestorage-5.2.3/lib/active_storage/attached.rb
spiral_form-0.1.0 vendor/bundle/gems/activestorage-5.2.3/lib/active_storage/attached.rb
activestorage-5.2.3 lib/active_storage/attached.rb