aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_storage/attached.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2017-07-06 11:33:29 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2017-07-06 11:33:29 +0200
commitc624df326a4ef36919a5195a3c5509fab97dcba3 (patch)
treea8e07aabde7548d5bd4a322a9898ad123cfa40f7 /lib/active_storage/attached.rb
parent5869045f2e71f0abdf3add19629d23a46b9fff0d (diff)
downloadrails-c624df326a4ef36919a5195a3c5509fab97dcba3.tar.gz
rails-c624df326a4ef36919a5195a3c5509fab97dcba3.tar.bz2
rails-c624df326a4ef36919a5195a3c5509fab97dcba3.zip
ActiveVault -> ActiveStorage
Yaroslav agreed to hand over the gem name ❤️
Diffstat (limited to 'lib/active_storage/attached.rb')
-rw-r--r--lib/active_storage/attached.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/active_storage/attached.rb b/lib/active_storage/attached.rb
new file mode 100644
index 0000000000..7475c38999
--- /dev/null
+++ b/lib/active_storage/attached.rb
@@ -0,0 +1,34 @@
+require "active_storage/blob"
+require "active_storage/attachment"
+
+require "action_dispatch/http/upload"
+require "active_support/core_ext/module/delegation"
+
+class ActiveStorage::Attached
+ attr_reader :name, :record
+
+ def initialize(name, record)
+ @name, @record = name, record
+ end
+
+ private
+ def create_blob_from(attachable)
+ case attachable
+ when ActiveStorage::Blob
+ attachable
+ when ActionDispatch::Http::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)
+ else
+ nil
+ end
+ end
+end
+
+require "active_storage/attached/one"
+require "active_storage/attached/many"
+require "active_storage/attached/macros"