diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-05 16:09:41 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-05 16:09:41 +0200 |
commit | b7cc003aa0aada594cb18ab80c13c13c75bcd389 (patch) | |
tree | e42658bfa9441c788d3c0c88680d2e92e0159469 /lib/active_vault/attached.rb | |
parent | aaf841518866b34d769d9a951a389d1eef70d6e7 (diff) | |
download | rails-b7cc003aa0aada594cb18ab80c13c13c75bcd389.tar.gz rails-b7cc003aa0aada594cb18ab80c13c13c75bcd389.tar.bz2 rails-b7cc003aa0aada594cb18ab80c13c13c75bcd389.zip |
Attached one and many
Diffstat (limited to 'lib/active_vault/attached.rb')
-rw-r--r-- | lib/active_vault/attached.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/active_vault/attached.rb b/lib/active_vault/attached.rb new file mode 100644 index 0000000000..a968f3500d --- /dev/null +++ b/lib/active_vault/attached.rb @@ -0,0 +1,34 @@ +require "active_vault/blob" +require "active_vault/attachment" + +require "action_dispatch/http/upload" +require "active_support/core_ext/module/delegation" + +class ActiveVault::Attached + attr_reader :name, :record + + def initialize(name, record) + @name, @record = name, record + end + + private + def create_blob_from(attachable) + case attachable + when ActiveVault::Blob + attachable + when ActionDispatch::Http::UploadedFile + ActiveVault::Blob.create_after_upload! \ + io: attachable.open, + filename: attachable.original_filename, + content_type: attachable.content_type + when Hash + ActiveVault::Blob.create_after_upload!(attachable) + else + nil + end + end +end + +require "active_vault/attached/one" +require "active_vault/attached/many" +require "active_vault/attached/macros" |